Public Member Functions | |
def | __call__ |
def | __init__ |
def | add_handlers |
def | add_transform |
def | listen |
def | log_request |
def | reverse_url |
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 |
Private Attributes | |
_wsgi |
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. Each tuple can contain an optional third element, which should be a dictionary if it is present. That dictionary is passed as keyword arguments to the contructor of the handler. This pattern is used for the StaticFileHandler below (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. .. attribute:: settings Additonal keyword arguments passed to the constructor are saved in the `settings` dictionary, and are often referred to in documentation as "application settings".
def tornado.web.Application.__init__ | ( | self, | |
handlers = None , |
|||
default_host = "" , |
|||
transforms = None , |
|||
wsgi = False , |
|||
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 | |||
) |
Appends the given handlers to our handler list. Note that host patterns are processed sequentially in the order they were added, and only the first matching pattern is used. This means that all handlers for a given host must be added in a single add_handlers call.
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 are passed to the HTTPServer constructor. For advanced uses (e.g. preforking), do not use this method; create an HTTPServer and call its bind/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 | |||
) |
tornado::web.Application::_wsgi [private] |