Flask - 没有外部文件的模板

时间:2014-05-18 13:18:39

标签: python templates flask

是否可以像在Bottle中一样使用Flask中的模板,而不使用任何外部文件?只是一个简单的字符串变量中的模板。这会怎么样?

1 个答案:

答案 0 :(得分:2)

使用flask.render_template_string()呈现存储在字符串中的模板。

from flask import render_template_string

return render_template_string(
    '<body>{{ greeting }}</body>',
    greeting='Hello, World!')
相关问题