Tornado routes¶
Decorator for a tornado.web.RequestHandler configuring the route and initialization dict.
The Route decorator stores all routes inside a class level list. You can then add all routes to the application using the Route.routes method. Some examples:
from tornadotools.route import Route
@Route(r"/")
class SimpleHandler(RequestHandler):
pass
@Route(r"/test_with_name", name="test")
class SimpleHandler2(RequestHandler):
pass
@Route(r"/test_with_init", initialize={'init': 'dictionary'})
class SimpleHandler3(RequestHandler):
pass
app = Application([
# other routes
] + Route.routes()
)
Tornado also support multiple hosts. When you want to use this with the Route decorator, you have to create the tornado.web.Application like this:
from tornadotools.route import Route
@Route(r"/.*", host="www\.example\.com")
class HostHandler(RequestHandler):
pass
app = Application([])
Route.routes(app)