擅长:python、mysql、java
<p>您还可以研究<a href="http://jinja.pocoo.org/2/documentation/templates#whitespace-control" rel="noreferrer">Jinja's built-in whitespace control</a>,这可能会减少在呈现模板后手动删除空白的需要。</p>
<p>引用<a href="http://jinja.pocoo.org/2/documentation/templates#whitespace-control" rel="noreferrer">the docs</a>:</p>
<blockquote>
<p>But you can also strip whitespace in templates by hand. If you put an minus sign (-) to the start or end of an block (for example a for tag), a comment or variable expression you can remove the whitespaces after or before that block:</p>
</blockquote>
<pre><code>{% for item in seq -%}
{{ item }}
{%- endfor %}
</code></pre>
<blockquote>
<p>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.</p>
</blockquote>