从python字典到django模板的数据。 [英] Present data from python dictionary to django template.?
本文介绍了从python字典到django模板的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字典
data = {'sok': [ [1, 10] ], 'sao': [ [1, 10] ],'sok&sao':[ [2,20]] }
我如何(循环字典)将我的数据作为(HTML)表呈现给Django模板。
这种格式,如表
How Can I (Loop trough Dictionary ) present My data as (HTML) table to Django template.?? This format that as table
author qty Amount
sok 1 10
sao 1 10
sok&sao 2 20
total
推荐答案
您可以使用 dict.items()
方法获取字典元素:
You can use the dict.items()
method to get the dictionary elements:
<table>
<tr>
<td>author</td>
<td>qty</td>
<td>Amount</td>
</tr>
{% for author, values in data.items %}
<tr>
<td>{{author}}</td>
{% for v in values.0 %}
<td>{{v}}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
这篇关于从python字典到django模板的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文