【发布时间】:2019-11-07 10:38:54
【问题描述】:
我有这样的列标题列表:
ColumnName = ['Latitude', 'Longitude', 'Depth']
还有一个格式如下的字典:
MyDict = [{'Latitude': '75',
'Longitude': '37',
'Depth': 6.0},
{'Latitude': '23',
'Longitude': '97',
'Depth': 2.3},
{'Latitude': '55',
'Longitude': '14',
'Depth': 1.9}]
我想用该数据制作动态表,并通过列表中的键访问字典值。我已经尝试在我的 django HTML 中使用此代码,但它不起作用
<table>
<thead>
<tr>
{% for ColName in ColumnName %}
<th> ColName <th>
{% endfor %}
<tr>
</thead>
<tbody>
{% for i in MyDict %}
<tr>
{% for x in ColumnName %}
<td>
{{i.x}}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
如果我使用
{{i.Latitude}}
它可以工作,但如果我使用 {{i.x}} 访问该数据,它就不起作用
【问题讨论】:
标签: django loops for-loop django-templates nested