如何将 url 参数添加到 Django 模板 url 标签? [英] How to add url parameters to Django template url tag?

查看:41
本文介绍了如何将 url 参数添加到 Django 模板 url 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,获取 url 参数是这样的:

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]

这篇关于如何将 url 参数添加到 Django 模板 url 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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