我有以下jinja2模板。当我渲染它时,“endif”语句后面的行没有正确的缩进。我试过传递trim_blocks = True和keep_trailing_newline = False没有太大的成功。Python jinja2注意和空白问题
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"
实际结果。 部门和支付块不按照数据的结构层次
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"
预期结果。 部门和支付对齐与支付,版本等
applications:
appication1:
version: "1.0"
dependencies:
- database: mysql
- storage: nfs
departments:
- accounting: payroll
paid: "yes"
obsolete: "no"
我想知道我可能会错过什么。
感谢,
谢谢你的提示! '{% - 如果环境不是none:%} 环境: {% - 为键,在environment.items值()%} - {{键}}:{{值}} {% - endfor - %} {% - endif%}' –