Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why two ViewSets have identical url in DRF?

Why two different viewsets have identical url? How can I change it?

router = routers.DefaultRouter()
router.register(r'general-worker', GeneralWorkerViewSet)
router.register(r'full-info-worker', FullInfoWorkerViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/', include(router.urls)),
    path('api/v1/drf-auth/', include('rest_framework.urls')),
]

json from http://127.0.0.1:8000/api/v1/

{
    "general-worker": "http://127.0.0.1:8000/api/v1/full-info-worker/",
    "full-info-worker": "http://127.0.0.1:8000/api/v1/full-info-worker/"
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

i can not solve your example, we have not enough information.
I can imagine, it can help:

router.register(r'general-worker', GeneralWorkerViewSet, basename='generalWorker')
router.register(r'full-info-worker', FullInfoWorkerViewSet, basename='fullInfoWorker')

try to use basename parameter.
docs here:
https://www.django-rest-framework.org/api-guide/routers/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading