Python烧瓶渲染像变量render_template的文本 [英] Python Flask Render Text from Variable like render_template

查看:191
本文介绍了Python烧瓶渲染像变量render_template的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道烧瓶功能 render_template 。我必须提供模板的文件名称。但是现在我想呈现模板的字符串(即模板的内容)。这就说得通了。但我现在不想解释为什么。我怎样才能渲染模板的文本?

pocoo.org/docs/0.10/api/#flask.render_template_stringrel =noreferrer> render_template_string

 >>> from flask import render_template_string 
>>> render_template_string('hello {{what}}',what ='world')
'hello world'


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烧瓶渲染像变量render_template的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆