我想在jinja2模板中使用css设置文本颜色。在下面的代码中,如果变量包含一个字符串,我想设置输出字符串以特定的字体颜色打印。每次生成的模板,虽然它在红色打印由于else语句,它永远不会看到前两个条件,即使输出应匹配,我可以告诉从变量输出是什么时,表生成,它是如预期。我知道我的CSS是正确的,因为默认情况下将字符串打印为红色。Jinja2模板不能正确渲染if-elif-else语句
我的第一个想法是把我正在检查的字符串括起来,但没有奏效。接下来是神社没有扩大RepoOutput[RepoName.index(repo)]
但对于上述循环它的工作原理,RepoName
是在适当扩大。我知道,如果我加括号,将打印的我相当肯定要么打破模板或只是不工作的变量。
我试着查看这些网站,并查看了全局表达式列表,但找不到类似于我的任何示例或进一步查看的方向。
http://jinja.pocoo.org/docs/templates/#if
http://wsgiarea.pocoo.org/jinja/docs/conditions.html
{% for repo in RepoName %}
<tr>
<td> <a href="http://mongit201.be.monster.com/icinga/{{ repo }}">{{ repo }}</a> </td>
{% if error in RepoOutput[RepoName.index(repo)] %}
<td id=error> {{ RepoOutput[RepoName.index(repo)] }} </td> <!-- I want this in green if it is up-to-date, otherwise I want it in red -->
{% elif Already in RepoOutput[RepoName.index(repo) %}
<td id=good> {{ RepoOutput[RepoName.index(repo)] }} </td> <!-- I want this in green if it is up-to-date, otherwise I want it in red -->
{% else %}
<td id=error> {{ RepoOutput[RepoName.index(repo)] }} </td> <!-- I want this in green if it is up-to-date, otherwise I want it in red -->
</tr>
{% endif %}
{% endfor %}
感谢
是'error'和'Already'意思是串在这里? –
你的意思了'elif'标签与'{$'开始? –
从逻辑上讲,'id = error'总是被设置,除非'已经在RepoOutput [RepoName.index(repo)'中为真;这可以让你在这里测试一个分支。 –