[Solved]-How to reverse a url that is using DefaultRouter()?

20👍

Firstly, the base_name kwarg to routers is deprecated in favor of the basename kwarg in DRF 3.11, however this should not be what’s causing issues. I can’t actually see anything wrong with the code sample you’ve provided either.

What I would recommend is try installing the django-extensions package. After you have installed and configured django-extensions, you can use the python manage.py show_urls command to output a list of all your routes.

python manage.py show_urls

/api/accounts/users/ accounts.views.UserViewSet account:user-list
/api/accounts/users/<uuid>/ accounts.views.UserViewSet account:user-detail

Each line contains the url /api/accounts/users/<uuid>/, the view’s path accounts.views.UserViewSet, and the name (this is what you want for reverse) of the route account:user-detail. With this I hope you will be able to find the correct name for your route. The URL portion also indicates any parameters required for that route.

Leave a comment