use forloop.counter0 to index an array in Django
I am trying to access the contents of an array using forloop.counter0
in django templates but I can't get it working.
What I have is
{% for action in my_action_list %}
{{another_list.forloop.counter0}}
{% endfor %}
Where my_action_list
is a list and another_list
is also a list. I have tried doing this manually e.g. {{another_list.0}}
and this works and I have also tried {{for开发者_StackOverflow社区loop.counter0}}
and this is printing out the correct index so not sure why its not working.
Any ideas?
The templating engine is probably looking for a property called another_list.forloop
, which of course doesn't exist.
If you want to loop through two lists simultaneously, the best solution may be to zip
them in your view beforehand.
精彩评论