gpt4 book ai didi

python - 如何在 Django 模板中迭代元组索引

转载 作者:太空宇宙 更新时间:2023-11-04 01:39:29 25 4
gpt4 key购买 nike

假设我有这个

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 \%}

最佳答案

不,你不想。以与外部列表完全相同的方式遍历内部列表。

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

关于python - 如何在 Django 模板中迭代元组索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com