Jinja模板变量语法

2024-04-25 03:33:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: 模板indexpageactivevs赋值set区别
1条回答
网友
1楼 · 发布于 2024-04-25 03:33:35

第二个将删除后面的空白。正如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.

相关问题 更多 >