DEV Community

Discussion on: Enumerating Through Lists in a Django Template

Collapse
 
waylonwalker profile image
Waylon Walker

Interesting, I have never seen a Django template before. If there are nested loops is there a way to distinguish between inner and outer for loops. This magical for loop variable seems a bit mysterious to me. I have never really reached for a template language and mostly stuck with the built-in string Template for my very limited use of templates.

Collapse
 
greenteabiscuit profile image
Reishi Mitani

Sorry for the late reply.
For two loops, it seems like there is the forloop.parentloop .
e.g. forloop.parentloop.counter
However for three or more loops I do not know yet whether there is a way to distinguish each of them.

This stackoverflow might be of a help: stackoverflow.com/questions/237651...