get router url name when testing in Django Rest Framework

DRF adds suffixes in viewsets for different URLs – list, detail and possibly custom URLs. You can see that in source code and in docs. So in your case the actual reverse should be something like:

reverse('api:my_list-list')    # for list URL. e.g. /api/my-list/
reverse('api:my_list-detail')  # for detail URL. e.g. /api/my-list/<pk>/

That is why its also probably better to use a resource name as a router base_name. For example base_name="user" vs base_name="users_list".

Leave a Comment