Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created August 10, 2012 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjgiridhar/3311136 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3311136 to your computer and use it in GitHub Desktop.
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