Reputation: 25
i am following flask template to display a list of items in my html template but the for loop only displaying last value
{'reference': 'Customer/bJxi0A3', 'display': 'TEST, Beacon'}
from the list below can't understand why ?
{'reference': 'Customer/uH50Lnw3', 'display': 'DEFVERIFYTESTONE, Awiltthirtyfive'}
{'reference': 'Customer/eereURJQ3', 'display': 'FITTESTTWO, Abcnsixteen'}
{'reference': 'Customer/URJQ3', 'display': 'FITTESTTWO, Abcnsixteen'}
{'reference': 'Customer/bJxi0A3', 'display': 'TEST, Beacon'}
What do i need to do with this for loop to display all the values ?
{% for item, value in customer.items(): %}
<tr>
<td>{{ item }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
Upvotes: 1
Views: 2385
Reputation: 291
You need to create another for loop, that goes through the list of all dicts. For example:
dict_list = [{'reference': 'Customer/uH50Lnw3', 'display': 'DEFVERIFYTESTONE, Awiltthirtyfive'},
{'reference': 'Customer/eereURJQ3', 'display': 'FITTESTTWO, Abcnsixteen'},
{'reference': 'Customer/URJQ3', 'display': 'FITTESTTWO, Abcnsixteen'},
{'reference': 'Customer/bJxi0A3', 'display': 'TEST, Beacon'}]
{% for i in dict_list: %}
{% for item, value in i.items(): %}
<tr>
<td>{{ item }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
{% endfor %}
Upvotes: 1