我需要在龙卷风中呈现html字符串的响应,如下所示:
self.method_to_render_html_from_string('<h1>Hello</h1>')
我该怎么做呢?龙卷风版本为6.1。现在它是如何显示的:在这里输入图像描述
与龙卷风无关的答案也值得赞赏:)
发布于 2022-01-17 17:52:32
如果要发送响应,请使用self.write
def get(self):
self.write('<h1>Hello</h1>')如果要从模板字符串生成html,则使用tornado.template.Template
from tornado.template import Template
def get(string):
t = Template('<h1>Hello {{ name }}</h1>')
self.write(t.generate(name='John'))更新:
如果响应是以纯文本形式发送的,则可以尝试将Content-Type: text/html头设置为将响应发送为HTML:
def get(self):
self.set_header('Content-Type', 'text/html')
self.write('<h1>Hello</h1>)https://stackoverflow.com/questions/70743738
复制相似问题