python Jinja2 If 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1461484/
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-11-03 22:18:55  来源:igfitidea点击:

Jinja2 If Statement

pythonjinja2

提问by Owen Pierce

The code below is a sample form I'm using to learn jinja2. As written, it returns an error saying that it doesn't recognize the {% endif %} tag. Why does this happen?

下面的代码是我用来学习 jinja2 的示例表单。正如所写,它返回一个错误,指出它无法识别 {% endif %} 标签。为什么会发生这种情况?

<html>

Name: {{ name }}
Print {{ num }} times
Color: {{ color }}
{% if convert_to_upper %}Case: Upper
{% elif not convert_to_upper %}Case: Lower{% endif %}




{% for repeats in range(0,num) %}
{% if convert_to_upper %}
{% filter upper %}
{% endif %}
<li><p style="color:{{ color }}">{{ name }}</style></li>
{% endfilter %}
{% endfor %}
</html>

回答by SilentGhost

I think you have your lines mixed up. Your endifcomese before endfilterwhereas ifis before filter. That's just a syntax error.

我想你的台词搞混了。你endif来之前endfilter而是if之前filter。那只是一个语法错误。