我正在尝试在jinja2模板中使用CSS设置文本颜色。在下面的代码中,如果变量包含字符串,则要将输出字符串设置为以特定字体颜色打印。每次生成模板时,由于else语句,它都会打印为红色,即使输出应该匹配前两个条件,我可以在表格生成时看到变量的输出,而它也是预期的。我知道我的css是正确的,因为默认情况下它以红色打印字符串。
我的第一个想法是将我检查的字符串用引号括起来,但那并没有起作用。接下来,我认为jinja没有扩展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 %}
谢谢