给定我有两个变量{{ profile }},它们的值分别为“ test”和{{ element.author }}“ test”。在jinja2中,当我尝试使用if比较它们时,没有任何显示。我做如下比较:
{{ profile }}
{{ element.author }}
{% if profile == element.author %} {{ profile }} and {{ element.author }} are same {% else %} {{ profile }} and {{ element.author }} are **not** same {% endif %}
我得到的输出test and test are not same怎么了,我该如何比较?
test and test are not same
只需使用诸如{{ var|string() }}或https://stackoverflow.com/a/19993378/1232796的过滤器{{ var|int() }}
{{ var|string() }}
{{ var|int() }}
在你的情况下,你想做
{% if profile|string() == element.author|string() %} {{ profile }} and {{ element.author }} are same {% else %} {{ profile }} and {{ element.author }} are **not** same {% endif %}