Tornado – Template – Extends

With the background of Tornado-Templates let’s solve bigger problems in web development. It maybe less complex to change welcome messages or usernames on a home page of the website, but it’s not so easy to cater to customization. For instance, gmail web client provides Settings and Themes that are customized for users. Even thought the base template (mail format, mail importance or chat pane) is same, Themes may differ based on customization set by the user.

Handling of customize is really trivial with Tornado. Here’s how..

In the above example, when custom.html is loaded, templateinheritance.html is first loaded as custom.html extends it. templateinheritance.html acts as a base template. {% block header %} and {% end %} block ensures customized information for username=John is addressed on the web page. So, with the base template, only the articles available for reading are shown but with custom.html ensures that when John logs-in he also gets to see the books he has read.

Base Template

Extended Template

One thought on “Tornado – Template – Extends

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.