[Django]-Using list index lookup within a template loop in django

5πŸ‘

βœ…

The easiest thing is probably to combine your lists in python and then just look through the combined list in the template:

combinedList = [(placeList[i],speakerList[i]) for i in range(4)]

{% for entry in combinedList %}
<tr>
<td>{{ entry.0 }}</td>
<td>1:30</td>
<td>{{ entry.1 }}</td>
</tr>
{% endfor %}

Or for transparency, you could make combinedList a list of objects or dictionaries for example:

combinedList = [{'place':placeList[i],'speaker':speakerList[i]} for i in range(4)]

{% for entry in combinedList %}
<tr>
<td>{{ entry.place }}</td>
<td>1:30</td>
<td>{{ entry.speaker }}</td>
</tr>
{% endfor %}
πŸ‘€ed.

0πŸ‘

You could aggregate these two lists in one.

For example:

yourlist = [('park','bill'),('store','john'),('home','jake'),...]
πŸ‘€Diego Navarro

Leave a comment