开发者

use forloop.counter0 to index an array in Django

开发者 https://www.devze.com 2023-01-08 19:44 出处:网络
I am trying to access the contents of an array using forloop.counter0 in django templates but I can\'t get it working.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号