【发布时间】:2014-03-28 07:02:59
【问题描述】:
我正在尝试在 jinja2 模板中使用 css 设置文本颜色。在以下代码中,如果变量包含字符串,我想将输出字符串设置为以特定字体颜色打印。每次生成模板时,尽管由于 else 语句而以红色打印,但即使输出应该匹配,它也永远不会看到前两个条件,我可以知道当表生成时变量的输出是什么并且它是预期的.我知道我的 css 是正确的,因为默认情况下以红色打印字符串。
我的第一个想法是将要检查的字符串括在引号中,但这不起作用。接下来是 jinja 没有扩展 RepoOutput[RepoName.index(repo)] 但它上面的 for 循环有效,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 %}
谢谢
【问题讨论】:
标签: python css if-statement jinja2