我在urls.py中有这个:
urlpatterns = patterns('',
url(r'^ding/', include('ding.urls', namespace='ding', app_name='ding')),
这在我的ding / urls.py中:
urlpatterns = patterns('',
url(r'^$', views.sign_in, name='sign_in'),
url(r'^connect/$', views.connect, name='connect'),
url(r'^disconnect/$', views.disconnect, name='disconnect'),
#url(r'^disconnect/sign_in/$', RedirectView.as_view(url=reverse('sign_in')), name="disconnect_sign_in"),
url(r'^search$', views.search, name='search'),
url(r'^parsed_query/(?P<query>.+)/(?P<scroll_num>(\-|)\d+)/$', views.get_search_results, name='get_search_results'),
url(r'^parsed_query/', views.parsed_query, name='parsed_query'),
url(r'^parsed_query_redirect/', views.parsed_query_redirect, name='parsed_query_redirect'),
)
调用以下任何一项:
print reverse('sign_in', current_app='ding')
print reverse('connect', current_app='ding')
print reverse('disconnect', current_app='ding')
...
会导致NoReverseMatch错误。
有什么建议吗?
答案 0 :(得分:2)
reverse('ding:sign_in')
参考:https://docs.djangoproject.com/en/1.6/topics/http/urls/#topics-http-reversing-url-namespaces
确保您知道应用程序命名空间和实例命名空间之间的区别:
https://docs.djangoproject.com/en/1.6/topics/http/urls/#url-namespaces
我发现很少需要两者(但当然有很多用例)。