gpt4 book ai didi

python - 在 Django 模板中将列表转换为逗号分隔值

转载 作者:太空宇宙 更新时间:2023-11-04 06:50:17 24 4
gpt4 key购买 nike

在 View 中我可以做:

l = ['one', 'two', 'three']
', '.join(l)
>>> 'one, two, three'

有没有办法在模板中执行相同的操作,或者我是否需要创建自定义模板过滤器?

最佳答案

为此有一个内置过滤器。来自docs

Filter arguments that contain spaces must be quoted; for example, to join a list with commas and spaces you’d use {{ list|join:", " }}.

关于python - 在 Django 模板中将列表转换为逗号分隔值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369413/

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