【发布时间】:2016-11-22 00:49:12
【问题描述】:
我有以下 jinja2 模板。当我渲染它时,“endif”语句之后的行没有适当的缩进。我试过通过 trim_blocks=True 和 keep_trailing_newline=False 没有太大的成功。
applications:
{{ application_name }}:
version: {{ version }}
{% if dependencies is not none: -%}
dependencies:
{% for key, value in dependencies.items() -%}
- {{ key }}: {{ value }}
{% endfor -%}
{% endif -%}
{% if departments is not none: -%}
departments:
{% for key, value in departments.items() -%}
- {{ key }}: {{ value }}
{% endfor -%}
{% endif -%}
paid: "yes"
obsolete: "no"
实际结果。 departments 和 paid 块不遵循数据结构层次结构
applications:
appication1:
version: "1.0"
dependencies:
- database: mysql
- storage: nfs
departments: <- Indent is not correct
- accounting: payroll
paid: "yes" <- Indent is not correct
obsolete: "no"
预期结果。 departments 和 paid 与 paid、version 等保持一致。
applications:
appication1:
version: "1.0"
dependencies:
- database: mysql
- storage: nfs
departments:
- accounting: payroll
paid: "yes"
obsolete: "no"
我想知道我还缺少什么。
谢谢,
【问题讨论】: