[英]Dictionary to table in Django
I'm new to Django and so far have a difficult time learning it. 我是Django的新手,到目前为止还很难学习它。 Even though there is a lot of documentation I just can't put it together sometimes.
即使有很多文档,我也不能把它放在一起。 Now I am stuck on putting a dictionary to a table... (yes I went through the tutorials)
现在我被困在把字典放到桌子上......(是的,我通过了教程)
Django 1.6 and python 2.7 Django 1.6和python 2.7
view: 视图:
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
template(I tried alot of variations): 模板(我尝试了很多变化):
<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>
You need to make a list of ads instead of a dictionary, for example: 您需要制作广告列表而不是字典,例如:
def panel(request):
adlist = [{'title': 'haas', 'price': 12.50, 'bid': 50.0, 'seen': 23.11}]
return render(request, 'panel.html', {'adlist' : adlist})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.