Django URLs - can't reverse url in a template

howtodothis picture howtodothis · Nov 23, 2011 · Viewed 22.1k times · Source

I think I need a second pair of eyes.

The below example should be self explanatory.

All I need is to be able to reverse my url in the template.

/urls.py

urlpatterns = patterns('',
    (r'^products/', include('products.urls')),
)

/products/urls.py

from django.conf.urls.defaults import patterns, url

urlpatterns = patterns('products.views',
    url(r'^$', view="index", name="index"),
)

/templates/products/index.html

<a href="{% url products:index %}"> Products </a>

UPDATE

Full stacktrace - http://pastebin.com/9nLp4uP5

Answer

JOSEFtw picture JOSEFtw · Jun 2, 2014

The syntax changed after Django 1.5 Instead of doing this:

<a href="{% url products_index %}"> Products </a>

You should now do this(string instead):

<a href="{% url 'products_index' %}"> Products </a>