Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created August 1, 2012 08:14
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/3224884 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3224884 to your computer and use it in GitHub Desktop.
Tornado - Templates
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<table border="1">
{% for key,value in dict.items() %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% end %}
</table>
</body>
</html>
import tornado.ioloop
import tornado.web
import time
class ItWorks(tornado.web.RequestHandler):
def get(self):
self.write("It Works!!")
class Article(tornado.web.RequestHandler):
def get(self):
articles = {"tornado":"Python",
"phpcake":"PHP"}
self.render('template.html', title='Articles', dict=articles)
## title and dict is handled by template.html
application = tornado.web.Application([
(r"/", ItWorks),
(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