在Jinja中设置变量 [英] Set variable in jinja
本文介绍了在Jinja中设置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在Jinja中设置一个变量和另一个变量.我会解释,我有一个子菜单,我想显示哪个链接处于活动状态.我试过了:
I would like to know how can I set a variable with another variable in jinja. I will explain, I have got a submenu and I would like show which link is active. I tried this:
{% set active_link = {{recordtype}} -%}
其中recordtype是为我的模板指定的变量.
where recordtype is a variable given for my template.
推荐答案
{{ }}
告诉模板 print 值,这不适用于您尝试执行的表达式.相反,请使用{% set %}
模板标记,然后以与普通python代码相同的方式分配值.
{{ }}
tells the template to print the value, this won't work in expressions like you're trying to do. Instead, use the {% set %}
template tag and then assign the value the same way you would in normal python code.
{% set testing = 'it worked' %}
{% set another = testing %}
{{ another }}
结果:
it worked
这篇关于在Jinja中设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文