Public Member Functions | |
def | __call__ |
def | __init__ |
def | add_handlers |
def | add_transform |
def | listen |
def | log_request |
def | reverse_url |
def | start_request |
Public Attributes | |
default_host | |
handlers | |
named_handlers | |
settings | |
transforms | |
ui_methods | |
ui_modules | |
Private Member Functions | |
def | _get_host_handlers |
def | _load_ui_methods |
def | _load_ui_modules |
A collection of request handlers that make up a web application. Instances of this class are callable and can be passed directly to HTTPServer to serve the application:: application = web.Application([ (r"/", MainPageHandler), ]) http_server = httpserver.HTTPServer(application) http_server.listen(8080) ioloop.IOLoop.instance().start() The constructor for this class takes in a list of `URLSpec` objects or (regexp, request_class) tuples. When we receive requests, we iterate over the list in order and instantiate an instance of the first request class whose regexp matches the request path. The request class can be specified as either a class object or a (fully-qualified) name. Each tuple can contain additional elements, which correspond to the arguments to the `URLSpec` constructor. (Prior to Tornado 3.2, this only tuples of two or three elements were allowed). A dictionary may be passed as the third element of the tuple, which will be used as keyword arguments to the handler's constructor and `~RequestHandler.initialize` method. This pattern is used for the `StaticFileHandler` in this example (note that a `StaticFileHandler` can be installed automatically with the static_path setting described below):: application = web.Application([ (r"/static/(.*)", web.StaticFileHandler, {"path": "/var/www"}), ]) We support virtual hosts with the `add_handlers` method, which takes in a host regular expression as the first argument:: application.add_handlers(r"www\.myhost\.com", [ (r"/article/([0-9]+)", ArticleHandler), ]) You can serve static files by sending the ``static_path`` setting as a keyword argument. We will serve those files from the ``/static/`` URI (this is configurable with the ``static_url_prefix`` setting), and we will serve ``/favicon.ico`` and ``/robots.txt`` from the same directory. A custom subclass of `StaticFileHandler` can be specified with the ``static_handler_class`` setting.
def tornado.web.Application.__init__ | ( | self, | |
handlers = None , |
|||
default_host = "" , |
|||
transforms = None , |
|||
settings | |||
) |
def tornado.web.Application.__call__ | ( | self, | |
request | |||
) |
def tornado.web.Application._get_host_handlers | ( | self, | |
request | |||
) | [private] |
def tornado.web.Application._load_ui_methods | ( | self, | |
methods | |||
) | [private] |
def tornado.web.Application._load_ui_modules | ( | self, | |
modules | |||
) | [private] |
def tornado.web.Application.add_handlers | ( | self, | |
host_pattern, | |||
host_handlers | |||
) |
def tornado.web.Application.add_transform | ( | self, | |
transform_class | |||
) |
def tornado.web.Application.listen | ( | self, | |
port, | |||
address = "" , |
|||
kwargs | |||
) |
Starts an HTTP server for this application on the given port. This is a convenience alias for creating an `.HTTPServer` object and calling its listen method. Keyword arguments not supported by `HTTPServer.listen <.TCPServer.listen>` are passed to the `.HTTPServer` constructor. For advanced uses (e.g. multi-process mode), do not use this method; create an `.HTTPServer` and call its `.TCPServer.bind`/`.TCPServer.start` methods directly. Note that after calling this method you still need to call ``IOLoop.instance().start()`` to start the server.
def tornado.web.Application.log_request | ( | self, | |
handler | |||
) |
def tornado.web.Application.reverse_url | ( | self, | |
name, | |||
args | |||
) |
Returns a URL path for handler named ``name`` The handler must be added to the application as a named `URLSpec`. Args will be substituted for capturing groups in the `URLSpec` regex. They will be converted to strings if necessary, encoded as utf8, and url-escaped.
def tornado.web.Application.start_request | ( | self, | |
connection | |||
) |