比较字符串时出现Python Jinja错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15498027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:16:23  来源:igfitidea点击:

Python Jinja error while comparing string

pythonflaskjinja2

提问by Noor

I'm getting a problem while comparing two string in python:

比较python中的两个字符串时遇到问题:

this is working:

这是有效的:

{% for publication in publications %}
        {{ publications[publication].pub_type }}
{% endfor %}

but not this:

但不是这个:

{% for publication in publications %}
        {% if publications[publication].pub_type equals "conference_paper" %} 
             class="active" 
         {% endif %}
{% endfor %}

In the above code, I'm just testing something, but its not working

在上面的代码中,我只是在测试一些东西,但它不起作用

I'm getting this error:

我收到此错误:

jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: expected token 'end of statement block', got 'equals'

采纳答案by SingleNegationElimination

perhaps you want:

也许你想要:

{% if publication.pub_type == "conference_paper" %}
{#                         ^^                    #}

equalsis not valid jinja2 syntax

equals是不是有效Jinja2的语法