Turtle Turtle - 2 months ago 29
Python Question

Django Url.py Parameters

I followed the Django tutorial on how to use the url dispatcher, but for the life of me cannot figure out why I am getting this error.

Reverse for 'details' with arguments '('my_address',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['details(?P<zip>[0-9]+)/$']

My url.py:

url(r'^details(?P<zip>[0-9]+)/$', views.search_details, name='details'),

The url used in my template:
<h1><a href="{% url 'details' data.zip%}">Data for {{data.zip}}</a></h1>

My view method declaration:

def search_details(request,zip):

When I try remove the parameter(zip) from the above code, the template renders, so I would believe the url is correct.


Your zip parameter matches digits from 0 to 9. The string "my_address" is not made up of those digits.

You should either pass a real zip, assuming those actually are numeric rather than alphabetic, or use a different pattern such as \w+.