Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created August 2, 2012 13:22
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/3237076 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3237076 to your computer and use it in GitHub Desktop.
Tornado - Template - Extends
{%extends "templateinheritance.html" %}
{% block header %}
<table border="1">
<tr>
<td>Article2</td>
<td>Author2</td>
</tr>
{% end %}
<html>
<head>
<title>Articles</title>
</head>
<body>
<h4>Articles available</h4>
<table border="1">
<tr>
<td>Article1</td>
<td>Author1</td>
</tr>
<tr>
<td>Article2</td>
<td>Author2</td>
</tr>
<tr>
<td>Article3</td>
<td>Author3</td>
</tr>
</table>
<h4> {{ username }}, you've read these articles</h4>
{% block header %}
<table border="1">
<tr>
<td>None</td>
<td>None</td>
</tr>
{% end %}
</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):
self.render('custom.html', username='John')
## 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