4
votes

I am getting an error creating a link in my Django template.

My template looks like this:

<a href="{% url 'location_detail' pk=location.id %}">{{ location.name }}</a>

My urls.py looks like:

url(r'^location(?P<pk>\d+)/$', views.location_detail, name="location_detail"),

My view looks like:

def location_detail(request, pk=None):

I get the error:

Reverse for views.location_detail with arguments '()' and keyword arguments '{u'pk': 1L}' not found.

I'm using Django 1.5 and python 2.7.2

Thanks!

2
Remove pk= in the template call - karthikr

2 Answers

10
votes

The problem was that I had a name space on the primary project urls.py:

url(r'^com/', include('com.urls', namespace="com")),

Changing the url to:

{% url 'com:location_detail' pk=location.id %}

That did the trick

3
votes

You have given your url pattern a name, so you should use that name in the {% url %} call:

{% url 'location_detail' pk=location.id %}