我到处搜索过,但找不到解决方案。如何在HTML电子邮件中插入列表?
mylist = [1, 2, 3, 4] # Can be longer and contain numbers and letters
# I have reduced my HTML Email code
html = """\
{% for i in mylist%}
<tr>
<td> {{ i }} </td>
</tr>
{& endfor &}
""".format(mylist)
我已经尝试过了,但是效果不佳。
感谢您的帮助。预先感谢
答案 0 :(得分:0)
{% endfor %}
而不是{& endfor &}
?
答案 1 :(得分:-1)
您可以将列表转换为字符串:
>>> mylist = [1, 2, 3, 4]
>>> str_mylist = str(mylist)
>>> str_mylist
'[1, 2, 3, 4]'
将此字符串添加到您的邮件中:
html = """
<tr>
<td> %s </td>
</tr>
""" % str_mylist