In a Django template, I want to access the elements in one list, whilst looping over elements in another list. So, I pass the lists mylist1
and mylist2
(both have the same number of elements) to the template as context variables, and I want to loop through mylist1
, display the element, and then also display the corresponding element of mylist2
. It would look something like this:
{% for result in mylist1 %}
<p>result</p>
<p>{{ mylist2.forloop.counter }}</p>
{% endfor %}
What's the correct solution?