Reputation: 1
I am trying to display a list in flask where every two items of a list are printed on a new row.
{% for x in sources| batch(2) %}
<h2>{{ sources}} </h2>
{% endfor %}
This works, but the items are displayed with brackets and quotes e.g. ['rain', 8.0]. I want to display them like rain : 8.0 How do i get rid of those brackets and quotes?
Edit: The sources list is: ['Decibel', 5, 'People', 3, 'Temperature', 2, 'Rain', 8, 'Time', 21]. I want to display it as Decibel, 5 and then on the next row People, 3 etc.
I also tried
{% for x in range(0, sources|length,2) %}
<h2>{{ sources[x],sources[x+1] }} </h2>
{% endfor %}
but then the quotes and brackets are also displayed.
This code below does not print the brackets and quotes, but only displays one item per row.
{% for x in sources %}
<h2>{{ x }} </h2>
{% endfor %}
Upvotes: 0
Views: 780
Reputation: 473
If you only use 2 elements
<h2> {{ x[0] }}: {{ x[1] }} </h2>
Or you can use:
{{ x|join(':') }}
it looks like the python join
Upvotes: 1