jinja2 在单引号中渲染字符串

jinja2 render string in single quote

通过 jinja2 模板生成 CF 清单时遇到问题。 jinja2 无法在单引号下输出 env 属性 in manifest.

template.yml.j2 模板文件有这个,

JBP_CONFIG_JAVA_MAIN:'{java_main_class: "com.test.example.GeneralService", arguments: "setup.yml"}'

最后的 manifest.yml 缺少单引号,

JBP_CONFIG_JAVA_MAIN: {java_main_class: "com.test.example.GeneralService", arguments: "setup.yml"}

清单中的预期输出, '{java_main_class: "com.test.example.GeneralService", arguments: "setup.yml"}' 带引号

我真的不明白为什么在呈现输出清单后省略了单引号。

使用 jinja,这很棘手但很容易做到,在您的模板文件中试试这个 -

JBP_CONFIG_JAVA_MAIN: "'{java_main_class: "com.test.example.GeneralService", arguments: "setup.yml"}'"

适合我。