我想做自定义通知系统。现在我在数据库中有表,有 html 代码,我放在我的页面上。 但是如果我在这段代码中插入 jinja 表达式,它们会显示为纯文本。
示例:
def render():
hidden_variable = "world"
example = "Hello {{hidden_variable}}!"
return {'example': example, 'hidden_variable': hidden_variable}
模板.html
<div>
{{example}}
</div>
我得到了什么:
Hello {{hidden_variable}}!
我想要的:
Hello world!
答案 0 :(得分:2)
那个 example 被存储为字符串,因为您在 python 函数中使用了 jinja 语法。
Jinja 是 Python 的 Web 模板引擎。
相反:
example = f"Hello {hidden_variable}!"