所以我决定尝试一下 Tornado (http://www.tornadoweb.org/),并且我已经取得了很大的进展,但是由于某种原因,每当我在 View 上调用 .generate() 函数时浏览器中会生成一个空白页面(但是 self.write() 可以工作)
我的 ReqHandler:
class Index(tornado.web.RequestHandler):
def get(self):
loader = template.Loader(funcs.static_prefix("/templates/"))
#self.write("Hello, world") #This works!
loader.load("test.html").generate(this="hello") #This doesn't :(
我的模板(test.html):
<html>
{{ this }}
</html>
我的日志:
13:43:18 web.1 | started with pid 21876
13:43:20 web.1 | WARNING:root:404 GET /favicon.ico (::1) 0.48ms
如您所见,如果出现错误,它会默默失败
有人可以帮忙吗?
最佳答案
generate
不会将渲染的模板写入输出。只需这样写:
self.render("test.html", this="hello")
并确保在应用的配置选项中设置模板路径。
关于python - Tornado 框架渲染空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877889/