5

I have this link in a template:

<a href="{% url show_item item.id %}">Item 1</a>

and this url in the urls.py

url(r'item/(?P<id>)/$', show_item, name="page_item")

however, this error occurs:

Reverse for 'show_item' with arguments '(63L,)' and keyword arguments '{}' not found.

I looked at this question:

how to get python to not append L to longs or ignore in django template

but it did not help.

Is there another way to use the primary key, which is an integer, in constructing URLs in templates?

Community
  • 1
  • 1
yretuta
  • 7,744
  • 17
  • 75
  • 146

2 Answers2

15

The URL name doesn't match. Change the template to be:

<a href="{% url page_item item.id %}">Item 1</a>
Ned Batchelder
  • 345,440
  • 70
  • 544
  • 649
1

It should be page_item not show_item in template.

iMom0
  • 11,861
  • 3
  • 48
  • 60