Python表中的字典 [英] Python dictionary in to html table
本文介绍了Python表中的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
返回render_template('index.html',result = result)$发送到HTML b $ b
现在我需要将结果字典中的元素作为表格打印到HTML中。 使用Jinja作为模板框架。您可以在您的模板(html)中执行以下操作:
< table>
{%for key,result.iteritems()中的值%}
< tr>
< th> {{key}}< / th>
< td> {{value}}< / td>
< / tr>
{%endfor%}
< / table>
Is there any way to print the python dictionary in to a table in HTML. I have a python dictionary and am sending to HTML by using
return render_template('index.html',result=result)
Now I need to print the elements in result dictionary in to HTML as a table.
解决方案
Flask uses Jinja as the templating framework. You can just do the following in your template (html)
<table>
{% for key, value in result.iteritems() %}
<tr>
<th> {{ key }} </th>
<td> {{ value }} </td>
</tr>
{% endfor %}
</table>
这篇关于Python表中的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文