如何将 url 参数添加到 Django 模板 url 标签?

编程入门 行业动态 更新时间:2024-10-14 04:24:37
本文介绍了如何将 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 标签?

本文发布于:2023-11-26 02:23:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   模板   参数   标签   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!