Skip to content

baixuexue123/tornado-boilerplate

 
 

Repository files navigation

tornado-boilerplate -- a standard layout for Tornado apps

Description

tornado-boilerplate is an attempt to set up an convention for Tornado app layouts, to assist in writing utilities to deploy such applications. A bit of convention can go a long way.

This app layout is the one assumed by buedafab.

Tested with Tornado v4.5

Related Projects

buedafab django-boilerplate python-webapp-etc comrade

Acknowledgements

The folks at Mozilla working on the next version of AMO were the primary inspiration for this layout.

Directory Structure

tornado-boilerplate/
    contrib/
    handlers/
        foo.py
        base.py
    schemas/
    static/
        css/
            vendor/
        js/
            vendor/
        images/
    store/
    templates/
    tests/
    app.py
    settings.py
    urls.py

handlers

All of your Tornado RequestHandlers go in this directory.

Everything in this directory is added to the PYTHONPATH when the environment.py file is imported.

static

A subfolder each for CSS, Javascript and images. Third-party files (e.g. the 960.gs CSS or jQuery) go in a vendor/ subfolder to keep your own code separate.

templates

Project-wide templates (i.e. those not belonging to any specific app in the handlers/ folder). The boilerplate includes a base.html template that defines these blocks:

title - Text for the browser title bar. You can set a default here and append/prepend to it in sub-templates using {{ super }}.

site_css - Primary CSS files for the site. By default, includes media/css/reset.css and media/css/base.css.

css - Optional page-specific CSS - empty by default. Use this block if a page needs an extra CSS file or two, but doesn't want to wipe out the files already linked via the site_css block.

extra_head - Any extra content for between the <head> tags.

header -Top of the body, inside a div with the ID header.

content - After the header, inside a div with the ID content.

footer - After content, inside a div with the ID footer.

site_js - After all body content, includes site-wide Javascript files. By default, includes media/js/application.js and jQuery. In deployed environments, links to a copy of jQuery on Google's CDN. If running in solo development mode, links to a local copy of jQuery from the media/ directory - because the best way to fight snakes on a plane is with jQuery on a plane.

js - Just like the css block, use the js block for page-specific Javascript files when you don't want to wipe out the site-wide defaults in site_js.

TODO

This needs to be tested with Tornado's templating language. A quick look at the documentation indicates that this basic template is compatible, but none of our Tornado applications are using templates at the moment, so it hasn't been tested.

Files

app.py

The main Tornado application, and also a runnable file that starts the Tornado server.

settings.py

A place to collect application settings ala Django. There's undoubtedly a better way to do this, considering all of the flak Django is taking lately for this global configuration. For now, it works.

Contributing

If you have improvements or bug fixes:

  • Fork the repository on GitHub
  • File an issue for the bug fix/feature request in GitHub
  • Create a topic branch
  • Push your modifications to that branch
  • Send a pull request

Authors

About

A standard layout for Tornado apps

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.6%
  • HTML 0.4%