什么可能导致NoReverseMatch错误

时间:2011-11-09 07:56:28

标签: django django-urls

如果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错误。为什么呢?

1 个答案:

答案 0 :(得分:2)

从此处删除$

(r'^accounts/$', include('auth.urls')),

$表示该行的结尾,而不是您的情况。