Reputation: 402
I have a dictionary where value are in list
{
'Fees': ['88000', '88000'],
'ROll Number': ['I0', 'I1'],
'Mark': [10, 10]
}
So I am trying to insert this data in table, SO my Django template are
<table>
<thead>
<tr>
{% for k, v in loan_bank_info.items %}
<th>{{ k }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
{% for k, value in loan_bank_info.items %}
{% for v in value %}
<td>{{ v }}</td>
{% endfor %}
{% endfor %}
</tr>
</tbody>
</table>
but in table value are printing as follow,
Fees ROll Number Mark
88000 88000 I0 I1 10 10
But what I want is -
Fees ROll Number Mark
88000 I0 10
88000 I1 10
how to iterate over list value in Django template
Upvotes: 2
Views: 325
Reputation: 9931
You can just iterate over the list. Something like below
<tr>
{% for k, value in loan_bank_info.items %}
{% for v in value %}
{% for i in v %}
<td>{{ i }}</td>
{% endfor %}
{% endfor %}
{% endfor %}
</tr>
Upvotes: 1