[英]Cannot get the reverse URL from 3rd party packages in Django
I am aware of Django's reverse function: 我知道Django的反向功能:
from django.core.urlresolvers import reverse
reverse('my_view_name')
However, if I want to get the URL using reverse from a 3rd part package I get a NoReverseMatch
. 但是,如果我想从第3部分包中使用反向获取URL,我会得到NoReverseMatch
。
For example, take the package oauth2_provider where I want to get the token URL it provides. 例如,将包oauth2_provider放在我想要获取它提供的令牌URL的位置。
my include urls.py... 我的包含urls.py ...
url(r'^api/', include('oauth2_provider.urls', namespace='oauth2_provider')),
Then I do reverse('token')
and get 然后我做reverse('token')
并得到
NoReverseMatch: Reverse for 'token' with arguments '()' and keyword arguments '{}' not found. NoReverseMatch:反向'token',参数'()'和关键字参数'{}'未找到。 0 pattern(s) tried: [] 尝试过0种模式:[]
why? 为什么?
looking inside the package URL the name is token
here 看包里面URL名称是token
这里
您需要在撤消网址时指定命名空间:
reverse('oauth2_provider:token')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.