我试图在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 …Run Code Online (Sandbox Code Playgroud) 我看过其他几篇文章,包括:
创建带有图像的MIME电子邮件模板以使用python / django发送
这些以及smtplib和电子邮件的python文档使我离我很近。我正在使用下面的代码来创建嵌入了简单jpg的电子邮件。如果我将电子邮件发送给gmail,它将很好地显示嵌入的图像,但Outlook 2013无法显示。
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
From = ''
To = ''
msg = MIMEMultipart()
msg['Subject'] = 'image test message'
msg['From'] = From
msg['To'] = To
text = 'This is sample text from me'
html = '''
<html>
<head>
<title> this is a test title </title>
</head>
<body>
<p> Test me <br>
Another line <br>
This is the image you were looking for <img …Run Code Online (Sandbox Code Playgroud)