python - jinja2模板引擎中的这个 "-"是做什么的?

标签 python django google-app-engine templates jinja2

我正在学习 jinja2,因为 Google App Engine 推荐它。

我在维基百科上找到了这个例子:http://en.wikipedia.org/wiki/Jinja_%28template_engine%29

  {%- for item in item_list %}
    {{ item }}{% if not loop.last %},{% endif %}
  {%- endfor %}

“{%- for”中的“-”是什么意思?

另外,我在哪里可以找到 jinja2 示例(使用 Google App Engine 更好)?

非常感谢!

最佳答案

它抑制额外的垂直间距,通常在您不希望循环通过的元素之间的间距过大时使用。

If you put an minus sign (-) to the start or end of a block (for example a for tag), a comment or variable expression you can remove the whitespaces after or before that block

见:http://jinja.pocoo.org/docs/templates/#whitespace-control

关于python - jinja2模板引擎中的这个 "-"是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11813422/

相关文章:

java - 从客户端下载生成的pdf

javascript - 如何在页面中嵌入代码编辑器?

python - Pandas apply() 自定义函数使用多个列作为 "input"

python - 使django应用程序在特定时间通知人们

javascript - 在 Django 中的两个自定义标签之间传递变量

java - 使用 Spring boot 执行 Google Cloud App 时出现问题

java - 如何在 App Engine 中安排 cron 作业?

python - Git:按 merge 顺序提交

python - 将 Pandas 中的列解析为时间

mysql - 外部 SQL 行插入在同一函数调用中未显示在 Django 中