如何将网址参数添加到Django模板网址标签? [英] How to add url parameters to Django template url tag?
本文介绍了如何将网址参数添加到Django模板网址标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为要获取如下网址参数:
In my view to get url parameters like this:
date=request.GET.get('date','')
在我的url中,我试图以这种方式通过url模板标记传递参数:
In my url I am trying to pass parameters in this way with the url template tag like this:
<td><a href="{% url 'health:medication-record?date=01/01/2001' action='add' pk=entry.id %}" >Add To Log</a></td>
?之后的参数显然不起作用,如何传递此数据值以便通过get进行检索?
The parameter after the ? is obviously not working, how can I pass this data value in order to retrieve in with a get?
推荐答案
我找到了答案此处:是否可以传递查询通过Django的{%url%}模板标记添加参数?
只需将它们添加到末尾:
Simply add them to the end:
<a href="{% url myview %}?office=foobar">
For Django 1.5+
<a href="{% url 'myview' %}?office=foobar">
[没有其他要改进的地方,但是我在解决代码滴答时遇到了一个愚蠢的错误]
[there is nothing else to improve but I'm getting a stupid error when I fix the code ticks]
这篇关于如何将网址参数添加到Django模板网址标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文