This is a quick boilerplate to start building apps with Tornado. It has an almost similar organization of a Django project, as most people are familar with it. This is how it looks -
.
├── server.py
├── apps
│ ├── __init__.py
│ └── main
│ ├── __init__.py
│ ├── urls.py
│ └── views.py
├── __init__.py
├── settings.py
├── static
│ └── style.css
├── templates
│ ├── base.html
│ └── home.html
└── urls.py
Settings as a dictionary, with full reference
settings = {
# debug: If True the application runs in debug mode
'debug': True,
...
}
Added shell to play with the system
(venv) ~/Works/tornado-boilerplate/project$ python shell.py
>>> import tornado.web
>>>
Added apps folder to separate logic in modules
Enabled importing/including urls from different apps, maintaing pattern
from tornado.web import URLSpec as url
urls = [
url(r"/", HomeHandler),
url(r"/static/(.*)", web.StaticFileHandler, {"path": settings.get('static_path')}),
]
# this will include patterns from urls.py inside `main` app.
urls += include(r"/main/", "apps.main.urls")
/apps/main/urls.py
from tornado.web import URLSpec as url
urls = [
url(r"test/", TestHandler), # This is `/main/test/`
]
Showing message when starting and stoping the server
(venv) ~/Works/tornado-boilerplate/project$ python server.py
Starting server on http://127.0.0.1:8888
^C
Stopping server.