Here we set a variabler named settings and this will allow us to tell Tornado where we save our HTML/Javascript/CSS files. We have been going from a very basic file to more advanced versions of it through the lessons below.

Folder structure

root folder

  • static
  • templates
    • index.html
    • template.html

We no longer need to tell the MainHandler where the html files live and in future lessons it will be easier to have Tornado find out Javascript/css files.

Here are some examples of what we can add in the settings dictionary:

  • debug: A boolean indicating whether the application is in debug mode.
  • cookie_secret: A secret key used for signing cookies.
  • xsrf_cookies: A boolean indicating whether to use XSRF protection for cookies.
  • login_url: The URL to redirect to for login.
  • default_handler_class: The default handler class for 404 and 500 errors.
  • ui_modules: A dictionary of UI modules to be used in templates.
  • autoescape: A boolean indicating whether to automatically escape HTML in templates.
  • autoreload: A boolean indicating whether to automatically reload the application when changes are detected.
  • compiled_template_cache: A boolean indicating whether to cache compiled templates.
  • static_hash_cache: A boolean indicating whether to cache static file hashes.
  • serve_traceback: A boolean indicating whether to serve tracebacks in error responses.
# Webserver stuff
import tornado.ioloop
import tornado.web
# Utility libraries
import os.path
# route to index.html
class MainHandler(tornado.web.RequestHandler):
    def get(self):
                    page_title = 'This is Amazing!!!',
                    page_heading = 'Welcome to Tornado'
settings = dict(
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
# r"/" == root website address
application = tornado.web.Application([
    (r"/", MainHandler)
# Start the server at port n
if __name__ == "__main__":
    PortNumber = str(7777)
    print(r'Server Running at http://localhost:' + PortNumber + r'/')
    print(r'To close press ctrl + c')


  • {{ variable_name }} - notice how the double curly braces is how we are able to pass parameters from python to the html page.
<!DOCTYPE html>
  <title>{{ page_title }}</title>
    {% block content %}
    {% end block %}


{% extends "template.html" %}
{% block content %}
		<h2>{{ page_heading }}</h2>
		<p>This is the index page</p>
{% end block %}

Run the application