Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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