For my request handler, my template is defined as string, not a file. I tried rendering with this, but received this error:
File "c:\envs\pomo\lib\site-packages\tornado\template.py", line 365, in _create_template f = open(path, "rb")
SESSIONS_TEMPLATE = template.Template('''<html><body>
{{sessions}}
</body></html>
''')
class MyHandler(tornado.web.RequestHandler):
def get(self):
self.render(SESSIONS_TEMPLATE.generate(sessions=response))
Use self.finish instead of self.render:
class MyHandler(tornado.web.RequestHandler):
def get(self):
self.finish(SESSIONS_TEMPLATE.generate(sessions=response))
If you look at render() method you will see it uses render_string() method to generate string, inserts stuff like CSS and JS and then in the last line it uses finish() to actually create request. In your case all you have to do is that last call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With