Home > Blockchain >  Why two ViewSets have identical url in DRF?
Why two ViewSets have identical url in DRF?

Time:07-12

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/"
}

CodePudding user response:

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/

  • Related