[英]Send GET parameter on url_for inside HTML
I have the following code: 我有以下代码:
<ul>
{% for name in items %}
<li style="list-style-type: none;">
<a href="{{ url_for('content', values='{{name}}') }}">{{ items[name].title }}</a>
</li>
{% endfor %}
</ul>
I want to insert into the url_for
a GET parameter that will be the name of the item. 我想在
url_for
插入一个GET参数,该参数将是项目的名称。 When I get the value sent to my views.py
, I get the whole string '{{name}}'
. 当我将值发送到我的
views.py
,我得到整个字符串'{{name}}'
。
@app.route('/content', methods=['GET', 'POST'])
def content():
name = request.args.get('values')
print name
>> {{name}}
I've tried concatenating with +
like {{ url_for('content', values='"+{{name}}+"') }}">{{ items[name].title }}
, but it didn't work too. 我尝试使用
+
{{ url_for('content', values='"+{{name}}+"') }}">{{ items[name].title }}
,但它没有也工作。
Any clues on how to do that? 关于如何做到这一点的任何线索? Is it possible to send a POST param that way?
是否有可能以这种方式发送POST参数?
Just use the variable name
directly in the expression: 只需在表达式中直接使用变量
name
:
{{ url_for('content', values=name) }}
'{{name}}'
is a literal string with the characters {
, {
, n
, etc, not an interpolation of the variable. '{{name}}'
是一个带有字符{
, {
, n
等的文字字符串,而不是变量的插值。
Note that this is not a POST parameter; 请注意,这不是 POST参数; it is a URL query parameter (part of the URL after the
?
). 它是一个URL查询参数(在
?
之后的URL的一部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.