jk's blog

Django error: Reverse for ‘some-name’ with arguments ‘(1,)’ and keyword arguments ‘{}’ not found. 0 pattern(s) tried: []

A nice feature of the URL matching rules is that even if you have named arguments in the url(), like so:

 url(r'^items/(?P<pk>[0-9]+)/$', ItemDetailView.as_view(), name='item_detail'),

the system will accept a positional parameter, like so:

{% url 'item_detail' item.id %}

I was thinking that it was going to be particular about named parameters, and I was searching for information about passing named parameters to url, but it wasn’t necessary. Once again, misdirected by an error message.

(This all happened because I’m working through an old tutorial in the book by Forcier, Bissex, and Chun. It’s based on version 1.0 or something ancient, and a lot of things are different. So, it’s like a dual-tutorial. One is following along with their instruction, and another is reading a lot of docs and Stack Overflow to port the tutorials to the new system.)