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 app.py file to more advanced versions of it through the lessons below.
Folder structure
root folder
- static
- templates
- index.html
- template.html
- app.py
App.py
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.
template.html
- {{ variable_name }} - notice how the double curly braces is how we are able to pass parameters from python to the html page.
index.html
Run the application