如果urls.py和模板中没有错误,可能会导致NoReverseMatch
错误?
看看urls.py:
website.urls:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(r'^$','base.views.index', name='index'), # works fine
(r'^accounts/$', include('auth.urls')),
)
auth.urls:
from django.conf.urls.defaults import *
from auth.views import accounts
urlpatterns = patterns('',
url(r'^$' ,accounts, name='accounts'), #not working
)
带有标记{% url accounts %}
的模板给出了NoReverseMatch错误。为什么呢?
答案 0 :(得分:2)
从此处删除$
:
(r'^accounts/$', include('auth.urls')),
$
表示该行的结尾,而不是您的情况。