使用整数参数(主键)的模板从Django构建URL [英] Django Build URLs from template with integer param, the primary key

查看:26
本文介绍了使用整数参数(主键)的模板从Django构建URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模板中有此链接:

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

,该网址位于urls.py

and this url in the urls.py

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

但是,会发生此错误:

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

我看了这个问题:

但没有帮助.

在模板中构造URL时,还有另一种使用主键(整数)的方法吗?

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

推荐答案

URL名称不匹配.将模板更改为:

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

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

这篇关于使用整数参数(主键)的模板从Django构建URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆