如何遍历从Python / Tornado处理程序传递到Tornado模板的字典?我试过像 <div id="statistics-table"> {% for key, value in statistics %} {{key}} : {{value['number']}} {% end %} </div>但它不起作用,其中统计数据是字典statistics = { 1 : {'number' : 2}, 2 : {'number' : 8}}
2 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
>>> from tornado import template
>>> t = template.Template('''
... <div id="statistics-table">
... {% for key, value in statistics.items() %}
... {{key}} : {{value['number']}}
... {% end %}
... </div>
... ''')
>>> statistics = { 1 : {'number' : 2}, 2 : {'number' : 8}}
>>> print(t.generate(statistics=statistics))
<div id="statistics-table">
1 : 2
2 : 8
</div>
选择:
<div id="statistics-table">
{% for key in statistics %}
{{key}} : {{statistics[key]['number']}}
{% end %}
</div>
添加回答
举报
0/150
提交
取消