2011-07-07 16 views
2

假設我有這個如何循環元組指數在Django模板

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

現在不是有這個

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

我可以有另一種循環像

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

回答

3

不,你不想。以與外部列表完全相同的方式遍歷內部列表。

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

非常感謝你的朋友,我只是困惑 –