I wish to have the following table :
Brand Total Price
A 2 2
T 4 9
I 2 20
B 9 9
Total 17 40
while Brand=['A','T','I','B'];Total=[2,4,2,9] and Price=[2,9,20,9]
views.py
context['LUnique'] = range(1,LUnique+1)
Header.html
<div class="col-sm-3">
<table class="table table-bordered " border="1">
<tr>
<td colspan="4">JUSON Supermart</td>
</tr>
{% for i in LUnique %}
<tr>
<td>{{i.Brand|safe}}</td>
<td>{{i.Total|safe}}</td>
<td>{{i.Price|safe}}</td>
</tr>
{% endfor %}
</table>
</div>
Anyone can help me on this because above code not return the table as i wish.
First, aggregate all the three lists into tuples using zip function.
views.py
Brand = ['A', 'T', 'I', 'B']
Total = [2, 4, 2, 9]
Price = [2, 9, 20, 9]
context = {'LUnique': zip(Brand, Total, Price)}
Then, iterate over it.
header.html
<div class="col-sm-3">
<table class="table table-bordered " border="1">
<tr><td colspan="4">JUSON Supermart</td></tr>
{% for b, t, p in LUnique %}
<tr>
<td>{{b}}</td>
<td>{{t}}</td>
<td>{{p}}</td>
</tr>
{% endfor %}</table>
</div>
Result:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments