Django 1.4 yet another reverse NoReverseMatch error on a URL with parameters

522 Views Asked by At

Here's yet another reverse error.

The URLs work as expected. I have the basic functionality mapped out and can click around the site without any problem. It's only when I try to reverse the URL that an error is thrown. If I comment out the call to the reverse everything works as expected, otherwise I get an error.

Reverse for 'app_view_list' with arguments '()' and keyword arguments '{'id': 'idvalue', 'title': 'titlevalue'}' not found.

NoReverseMatch

I'm developing on Django 1.4 with the dev server.

Here is the code

urls.py

urlpatterns = patterns('',
    url(r'^list/$', 'app.views.browse_list', name='app_browse_lists'),
    url(r'^list/(?P<id>[0-9]*)/(?P<title>[0-9a-zA-Z-]*)/$', 'app.views.list', name='app_view_list'),
)

The function I'm targeting

views.py

def list(request, id, title):
    print reverse ('app_view_list', kwargs={'id': 'idvalue', 'title': 'titlevalue'})
    ...
1

There are 1 best solutions below

0
On BEST ANSWER

Are you actually passing idvalue? That won't match, as the id group is expecting a digit.

In any case, your regex would be better written:

r'^list/(?P<id>\d+)/(?P<title>[\d\s]+/$