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'嗎? –