Another django NoReverseMatch

烈酒焚心 提交于 2019-12-25 04:03:35

问题


In project.urls:

url(r'^category/', include('category.urls')),

In project/category/category.urls (patterns prefixed with 'project.category.views'):

url(r'^list/', 'category_list', name='category_list_name'),

In project/templates/base.html:

{% url 'category_list_name' %}

Gives me:

Caught NoReverseMatch while rendering: Reverse for ''category_list_name'' with arguments '()' and keyword arguments '{}' not found.

In the shell, I get the same error for this:

>>> reverse(category.views.category_list)

But this works fine:

>>> reverse("category_list_name")
u'/en/category/list/'

In a view, I get an empty string for reversing the named url. Like you see I'm also using localeurl, but I think that shouldn't matter?

Any ideas?


回答1:


{% url 'category_list_name' %} looks like you are using Django 1.3 but do you have {% load url from future %} in your template? If not you should use {% url category_list_name %} instead. Quotes make all the difference.



来源:https://stackoverflow.com/questions/7125168/another-django-noreversematch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!