Reputation: 5
I'm new to Django and so far have a difficult time learning it. 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
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>
Upvotes: 0
Views: 697
Reputation: 473763
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})
Upvotes: 2