Iterating through two lists in Django templates

You can use zip in your view:

mylist = zip(list1, list2)
context = {
            'mylist': mylist,
        }
return render(request, 'template.html', context)

and in your template use

{% for item1, item2 in mylist %}

to iterate through both lists.

This should work with all version of Django.

Leave a Comment