问题
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