0

This is how I defined urls.py file of my app


router = DefaultRouter()
router.register('hello-viewset', views.HelloViewSet, base_name='hello-viewset')
router.register('profiles', views.UserProfileViewSet)
router.register('schema', views.SchemaViewSet)
router.register('creddefination', views.CredDefViewSet)
router.register('overalltable', views.OverallViewSet)



urlpatterns = [

    path('', include(router.urls)),
]

urls.py of Project:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('DIAPI.urls')),

]

THis is my base API view I am not getting correct address for creddefination. But when i manually go to http://127.0.0.1:7000/api/creddefination/ it is working. It is just not displaying correctly. What might be reason for this

3
  • what does "not displaying correctly" mean ? Traceback ? empty list ? results with unexpected fields/values ? Commented Apr 24, 2020 at 10:15
  • as you can see in the image attached, in creddefination it is showing different address. When i comment out the part for overalltable, It is displaying correctly in UI. Commented Apr 24, 2020 at 10:38
  • My bad, I did not understand it correctly. Commented Apr 24, 2020 at 11:28

1 Answer 1

2

I guess views.CredDefViewSet and views.OverallViewSet are using the same model.

If that's true, then the default register's basename will be named after that model and used as name in a call to Django's reverse url construction. Since the API Root view will be trying to resolve both views with the same name, it'll lead to the same url.

Workaround is to explicitly add a basename to one of the view:

router.register('creddefination', views.CredDefViewSet, basename='creddeef')
Sign up to request clarification or add additional context in comments.

1 Comment

yes, they are both using the same model. I will try this in morning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.