gpt4 book ai didi

python - Jinja 模板变量语法

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

下面2个模板变量赋值有什么区别?

{% set active_page = 'index.htm' %}
---vs---
{% set active_page = 'index.htm' -%}

最佳答案

第二个将删除其后面的空白。正如 document 所说:

You can also strip whitespace in templates by hand. If you add a minus sign (-) to the start or end of a block (e.g. a For tag), a comment, or a variable expression, the whitespaces before or after that block will be removed:

{% for item in seq -%}
{{ item }}
{%- endfor %}

This will yield all elements without whitespace between them. If seq was a list of numbers from 1 to 9, the output would be 123456789.

关于python - Jinja 模板变量语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33325949/

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