Enumerating Through Lists

Hi, I am trying to generate a table with the for loop in Django. In the table, I need to use the counters of the outer and inner loops.

The table should be like this:
vA=0 vA=1 vA=2 …
vB=0 xx xx xx …
vB=1 xx xx xx …

I checked “forloop.parentloop” and it doesn’t exist in the documentation. I would be grateful if someone could suggest how to do it. Thanks in advance!

Hello there, maybe you can get around using with before your second for loop?

Hi Ieandrodesouzadev,

thanks so much for your suggestion!

I added {% with outcounter=forloop.counter|add:"-1" %} before the second for loop and it works.

By the way, may I ask how to search around the Django documentation? Somehow when I search for “with”, it returns nothing:

Thanks again!!

Sometimes the search doesn’t give the results properly.
I tend to look at the specific reference pages, when i’m searching for something, using terms like:

  • templatetags
  • models
  • model field
  • form field
  • forms

I see, thanks so much for your help!