我正在關注一本書(Practical Django Projects 2nd Ed。),並且我遇到了一個我無法弄清的錯誤。NoReverseMatch當在Django中使用{%url%}時
我得到這個錯誤:在/博客 TemplateSyntaxError/
Caught NoReverseMatch while rendering: Reverse for 'coltrane_category_list' with arguments '()' and keyword arguments '{}' not found.
這裏是我的模板使用{%URL%}代碼:
<li id="main-nav-entries">
<a href="{% url coltrane_entry_archive_index %}">Entries</a>
</li>
這裏是我的URL配置:
entry_info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
}
urlpatterns = patterns('django.views.generic.date_based',
(r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'),
(r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'),
)
錯誤是什麼意思?我沒有給出足夠的論據嗎? {%url%}如何工作?根據我的理解,它將查看URL配置並查找匹配的關鍵字,並根據URL配置中的匹配關鍵字返回一個URL。