I have a list of dictionaries as follows:
listDict = [{'product':'sandwich','price':'5200'}, {'product':'hamburger','price':'3000'}]
to iterate through the elements i do:
{%for element in listDict%}
{% for key,value in element.items %}
<input type="checkbox" name = "bar" value = "{{ value }}">{{ value }}<br>
{% endfor %}
{% endfor %}
this, as expected, will print:
sandwich
5200
hamburger
3000
but how could I concatenate the values in order to print something like this:
sandwich - 5200
hamburger - 3000
I can't do something like below:
for element in listDict:
element['product']+" - "+element['price']
Thanks in advance!
You can just do this:
{%for element in listDict%}
{{ element.product }} - {{ element.price }}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With