如何添加命名空间url到django-rest-framework路由器视图集 [英] How to add namespace url to a django-rest-framework router viewset
问题描述
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')),
)
可浏览的api查找url名称,如'user-list' / code>和
'user-detail'
仍然代替'api:user-list'
我想要发生什么。
我假设有一个简单的修复(这似乎是一个非常标准的事情要做),但我可以在django-rest-framework文档中找不到任何解决方案。如果我在文档中缺少某些内容,请分享一个链接,或者如果我接近这个错误(即为什么会这样做,这是不好的做法或者什么)请解释为什么或正确的方法来管理api urls是。谢谢!
有一个拉请求为此目前打开。请随时加入讨论。
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!
There's a pull request open for this currently. Please feel free to join the discussion.
这篇关于如何添加命名空间url到django-rest-framework路由器视图集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!