Python Flask 从变量渲染文本,如 render_template [英] Python Flask Render Text from Variable like render_template
本文介绍了Python Flask 从变量渲染文本,如 render_template的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道烧瓶函数render_template
.我必须给出模板的文件名.但现在我想呈现模板的字符串(即模板的内容).这就说得通了.但我现在不想解释为什么.如何简单地呈现模板的文本?
解决方案
您可以使用 render_template_string
:
I know the flask function render_template
. I have to give the file name of the template. But now I want to render the string of a template (that is the content of the template). That makes sense. but I don't want to explain now why. How can I render the text of a template simply?
解决方案
You can use render_template_string
:
>>> from flask import render_template_string
>>> render_template_string('hello {{ what }}', what='world')
'hello world'
这篇关于Python Flask 从变量渲染文本,如 render_template的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文