tej.tan
tej.tan

Reputation: 4177

How to iterate over tuple index in django template

Suppose i have this

mylst = [(a, b, c), (x, y, z), (l, m, n)]

now instead of having this

{\% for item in mylst \%}    
     {{ item.0 }} {{ item.1}} {{ item.2 }}    
{\% endfor \%}

can i have another loop like

{\% for item in mylst \%}    
     {\% for a in item.length \%}
             {{item.index  }}
     {\% endfor \%}
{\% endfor \%}

Upvotes: 2

Views: 2389

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

No, and you don't want to. Iterate through the inner list in exactly the same way as the outer one.

{% for item in mylst %}
    {% for a in item %}
        {{ a }}
    {% endfor %}
{% endfor %}

Upvotes: 3

Related Questions