Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add namespace url to a django-rest-framework router viewset

I would like to add a url namespace to my api router but when I do the router still looks for urls without a namespace:

router = DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'events', EventViewSet)
router.register(r'comments', CommentViewSet)

urlpatterns = patterns('apiroot.views',
                       url(r'^', include(router.urls, namespace='api')),
                       )

The browsable api looks for url names like 'user-list' and 'user-detail' still instead of 'api:user-list' which is what I would like to have happen.

I'm assuming there is an easy fix for this (it seems like a pretty standard thing to want to do) but I can't find any solution in the django-rest-framework docs. If I'm missing something from the docs, please share a link or if I am approaching this wrong (i.e "why would you do that, it's bad practice" or whatever) please explain why or what the correct way to manage api urls would be. Thanks!

like image 297
Will Farley Avatar asked Oct 26 '13 22:10

Will Farley


1 Answers

There's a pull request open for this currently. Please feel free to join the discussion.

like image 149
Carlton Gibson Avatar answered Oct 18 '22 18:10

Carlton Gibson