Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tornado - Template - Template() and Loader()
<html>{{ name }}</html>
import tornado.ioloop
import tornado.web
from tornado.template import Template
from tornado.template import Loader
class Article(tornado.web.RequestHandler):
def get(self):
## Works with Template method of tornado.template
t = Template("<html>{{ name }}</html>")
self.write(t.generate(name="John"))
## Works with Loader method of tornado.template
loader = Loader(".")
self.write(loader.load("template.html").generate(name="John"))
application = tornado.web.Application([
(r"/articles", Article),
],debug=True)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment