2
我想在django模板中使用forloop.counter0
訪問數組的內容,但我無法使它工作。使用forloop.counter0索引Django中的數組
我有什麼是
{% for action in my_action_list %}
{{another_list.forloop.counter0}}
{% endfor %}
凡my_action_list
是列表,another_list
也是一個列表。我嘗試過這樣手動{{another_list.0}}
和這個工程,我也試過{{forloop.counter0}}
,這是打印出正確的索引,所以不知道爲什麼它不工作。
任何想法?
+1:在視圖函數中儘可能多地做。如果模板變得複雜,請修復視圖功能。 – 2010-07-23 14:01:38