【发布时间】:2014-10-11 22:44:53
【问题描述】:
我试过了:
list1 = [{"username": "abhi", "pass": 2087}]
return render_template("file_output.html", list1=list1)
在模板中:
<table border=2>
<tr>
<td>
Key
</td>
<td>
Value
</td>
</tr>
{% for dictionary in list1 %}
{% for key in dictionary %}
<tr>
<td>
<h3>{{ key }}</h3>
</td>
<td>
<h3>{{ dictionary[key] }}</h3>
</td>
</tr>
{% endfor %}
{% endfor %}
</table>
上面的代码是将每个元素拆分成多个字符:
[
{
"
u
s
e
r
...
我在一个简单的 Python 脚本中测试了上面的嵌套循环,它工作正常,但在 Jinja 模板中却不行。
【问题讨论】:
标签: python dictionary flask iteration jinja2