q3d
q3d

Reputation: 3523

NoReverseMatch with Django when the URL exists

In a template, I have {% url "news.views.article" article=article.id %} where article.id is the ID of an article currently being displayed. My urls.py contains this:

url(r'^news/$', 'news.views.index'),
url(r'^news/article/(?P<article>\d{1,4})/$', 'news.views.article'),

However, when I load the page containing the above templatetag, I get this:

NoReverseMatch at /news/
Reverse for '"news.views.article"' with arguments '()' and keyword arguments '{'article': 2}' not found.

Upvotes: 2

Views: 690

Answers (2)

Tisho
Tisho

Reputation: 8502

The syntax with quotes around the view name works only for Django 1.5. Since you're probably using an older version, you should remove the quotes, or add in your template:

{% load url from future %}

and then use the quotes.

More info on the deprecation - Django 1.3 release notes

Upvotes: 0

Stieffers
Stieffers

Reputation: 752

Try it without the quotes around your view definition.

 {% url news.views.article article=article.id %}

You've already defined the view name, so this should work by calling the function by name.

Upvotes: 4

Related Questions