Add support for namespaces to DefaultRouter API Root. by rockymeza · Pull Request #2333 · encode/django-rest-framework (original) (raw)

@tomchristie, sorry for the confusion. Here is my use-case. I put my router URLs in a namespace like this:

urlpatterns = [ url('^api/', include(router.urls, namespace='api')), ]

And then when I go to the API Root, I get a page with no links. This is because when DefaultRouter create the APIRoot view, it tries to reverse the URLs without the namespace. Then the Api Root view just returns an empty dictionary, because all of the reversing failed.

That is why I added the namespace argument to the DefaultRouter. Now it will try to reverse the URLs using the namespace. This way, the API Root will successfully resolve the registered viewsets and will return data, as tested in the TestNamespacedDefaultRouter TestCase.

I hope this makes it clearer. Please let me know if you have more questions.


If I'm understanding correctly, I think this has little to do with what @thedrow was talking about with the documentation they added in #2335.