我有一个名为“标签”的数组元素,并希望将标签数组转换为由空格分隔的字符串。但是你在 Jinja 是怎么做到的呢?
我努力了:
{{ tags|join }}
You can use regular python in jinja tags. an obvious choice for some simple cases is str.join
:
>>> jinja2.Template(r'{{ " ".join(bar) }}').render(bar='baz')
u'b a z'.
You can also iterate over sequences in jinja with a for
block:
>>> jinja2.Template(r'{% for quux in bar %}{{ quux }} {% endfor %}').render(bar='baz')
u'b a z '