如何从 Jinja 中的字符串中删除尾随空格?

Aya*_* B. 5 jinja2

在我的情况下,所有字符串都是单字的,需要删除字符串中的尾随空格,例如, 'hello ''hello'; 'hello ''hello'

一种方法可以采用分体式,

{% if ' ' in word %}
  {% set word = word.split(' ')[0] %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)

这是有效的,因为字符串是一个词。我很确定一定有更好的方法。

Nic*_*mer 11

这不是.strip()……这是| trim。例如{{ some_variable_string_name | trim }}


Aya*_* B. 8

傻我!它.strip()'hello '.strip()