0
现在,我有鉴于一个字典,并希望存在于HTML表格的形式: 如何遍历包含Django模板中的许多字典的列表?
和我通过它的来龙去脉:
context['cities']=cities
然后,使其:
render(request,'index.html',context=context)
在 '的index.html':
<table>
<tr>
<th>name</th>
<th>population</th>
<th>country</th>
</tr>
{% for city in cities%}
<tr>
<td>{{city.name}}</td>
<td>{{city.population}}</td>
<td>{{city.country}}</td>
</tr>
{% endfor %}
</table>
不幸的是,似乎Django模板不能支持这种遍历,所以结果不能像我期望的那样成功显示。 “td”标签为空。
它应该工作,你能分享你的'views.py'吗? –