【发布时间】:2014-05-22 18:12:08
【问题描述】:
我是 Django 的新手,到目前为止学习它很困难。即使有很多文档,我有时也无法将它们放在一起。现在我被困在把字典放在桌子上......(是的,我已经完成了教程)
Django 1.6 和 python 2.7
查看:
def panel(request):
adlist = {}
adlist['title'] = 'haas','paas'
adlist['price'] = 12,50
adlist['bid'] = 50,0
adlist['seen'] = 23,11
context = {'adlist' : adlist}
return render(request, 'panel.html', context)enter code here
模板(我尝试了很多变体):
<table class="zebra">
<caption>Panel.</caption>
<thead>
<tr>
<th>title</th>
<th>price</th>
<th>bid</th>
<th>seen</th>
</tr>
</thead>
<tbody>
{% for ad in adlist %}
<tr>
<td>{{ ad.title }}</td>
<td>{{ ad.price}}</td>
<td>{{ ad.bid}}</td>
<td>{{ ad.seen}}</td>
</tr>
{% endfor %}
</tbody>
</table>
【问题讨论】:
标签: python django dictionary html-table