简体   繁体   English

Python Flask render_template() 忽略不是 var 的 {{text}}

[英]Python Flask render_template() ignore {{text}} that was not a var

I'm having a trouble using the render_template() Flask function.我在使用 render_template() Flask 函数时遇到了问题。

In my original template (html) I have a 'text' that is wrapped by {{}}, and it should not be interpreted as a variable for flask to print.在我的原始模板 (html) 中,我有一个由 {{}} 包裹的“文本”,它不应被解释为烧瓶打印的变量。 For example:例如:

{{InteractionDefaults.Email}}

{{content.Name}}

In this particular case, flask is converting correctly the {{content.Name}} because it's an object that I'm giving as parameter in the render_template function.在这种特殊情况下,flask 正确转换了 {{content.Name}},因为它是我在 render_template 函数中作为参数提供的对象。 But the ERROR here is when the flask try to render {{InteractionDefaults.Email}} object, since that string is not a object that i'm giving as parameter, because it's a static text that should be printed exactly that way "{{InteractionDefaults.Email}}" in the rendered template.但是这里的错误是当烧瓶尝试呈现 {{InteractionDefaults.Email}} 对象时,因为该字符串不是我作为参数提供的对象,因为它是一个静态文本,应该完全以这种方式打印“{{ InteractionDefaults.Email}}”在呈现的模板中。

The error is: 'InteractionDefaults' is undefined错误是:“InteractionDefaults”未定义

How can I say to flask do not interpreter this as a variable?我怎么能说烧瓶不要将其解释为变量? I tried something like我试过类似的东西

@{{InteractionDefaults.Email}}

But I think that didn't work.但我认为那没有用。

您可以通过将 {{ 括在双引号中来转义 {{,以便烧瓶将其解释为字符串,例如,

{{ "{{InteractionDefaults.Email}}" }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM