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,963
  • 17
  • 80
  • 151

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
  • 364,293
  • 75
  • 561
  • 662
1

It should be page_item not show_item in template.

iMom0
  • 12,493
  • 3
  • 49
  • 61