在 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:", " }}.
