为了账号安全,请及时绑定邮箱和手机立即绑定

如何遍历从Python / Tornado处理程序传递到Tornado模板的字典?

如何遍历从Python / Tornado处理程序传递到Tornado模板的字典?

蝴蝶刀刀 2021-03-30 22:11:36
如何遍历从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>


查看完整回答
反对 回复 2021-04-02
  • 2 回答
  • 0 关注
  • 224 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信