是否可以通过 Django 的 {% url %} 模板标签传递查询参数? [英] Is it possible to pass query parameters via Django's {% url %} template tag?
本文介绍了是否可以通过 Django 的 {% url %} 模板标签传递查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将请求参数添加到 {% url %}
标签,例如 ?office=foobar
.
I'd like to add request parameters to a {% url %}
tag, like ?office=foobar
.
这可能吗?我在上面找不到任何东西.
Is this possible? I can't find anything on it.
推荐答案
否,因为 GET 参数不是 URL 的一部分.
No, because the GET parameters are not part of the URL.
只需将它们添加到末尾:
Simply add them to the end:
<a href="{% url myview %}?office=foobar">
对于 Django 1.5+
For Django 1.5+
<a href="{% url 'myview' %}?office=foobar">
这篇关于是否可以通过 Django 的 {% url %} 模板标签传递查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文