tornado.web
RequestHandler
RequestHandler.initialize
RequestHandler.prepare
RequestHandler.on_finish
Implement any of the following methods (collectively known as the HTTP verb methods) to handle the corresponding HTTP method. These methods can be made asynchronous with one of the following decorators: .gen.coroutine, .return_future, or asynchronous.
RequestHandler.get
RequestHandler.post
RequestHandler.put
RequestHandler.delete
RequestHandler.head
RequestHandler.options
RequestHandler.get_argument
RequestHandler.get_arguments
RequestHandler.decode_argument
RequestHandler.request
The tornado.httpserver.HTTPRequest object containing additional request parameters including e.g. headers and body data.
RequestHandler.path_args
RequestHandler.path_kwargs
The path_args
and path_kwargs
attributes contain the positional and keyword arguments that are passed to the HTTP verb methods <verbs>
. These attributes are set before those methods are called, so the values are available during prepare.
RequestHandler.set_status
RequestHandler.set_header
RequestHandler.add_header
RequestHandler.clear_header
RequestHandler.set_default_headers
RequestHandler.write
RequestHandler.flush
RequestHandler.finish
RequestHandler.render
RequestHandler.render_string
RequestHandler.get_template_namespace
RequestHandler.redirect
RequestHandler.send_error
RequestHandler.write_error
RequestHandler.clear
RequestHandler.cookies
RequestHandler.get_cookie
RequestHandler.set_cookie
RequestHandler.clear_cookie
RequestHandler.clear_all_cookies
RequestHandler.get_secure_cookie
RequestHandler.set_secure_cookie
RequestHandler.create_signed_value
RequestHandler.application
The Application object serving this request
RequestHandler.async_callback
RequestHandler.check_xsrf_cookie
RequestHandler.compute_etag
RequestHandler.create_template_loader
RequestHandler.get_browser_locale
RequestHandler.get_current_user
RequestHandler.get_login_url
RequestHandler.get_status
RequestHandler.get_template_path
RequestHandler.get_user_locale
RequestHandler.log_exception
RequestHandler.on_connection_close
RequestHandler.require_setting
RequestHandler.reverse_url
RequestHandler.settings
RequestHandler.static_url
RequestHandler.xsrf_form_html
Application
settings
Additional keyword arguments passed to the constructor are saved in the settings dictionary, and are often referred to in documentation as "application settings". Settings are used to customize various aspects of Tornado (although in some cases richer customization is possible by overriding methods in a subclass of RequestHandler). Some applications also like to use the settings dictionary as a way to make application-specific settings available to handlers without using global variables. Settings used in Tornado are described below.
General settings:
debug
: IfTrue
the application runs in debug mode, described indebug-mode
.gzip
: IfTrue
, responses in textual formats will be gzipped automatically.log_function
: This function will be called at the end of every request to log the result (with one argument, the RequestHandler object). The default implementation writes to the logging module's root logger. May also be customized by overriding Application.log_request.ui_modules
andui_methods
: May be set to a mapping of UIModule or UI methods to be made available to templates. May be set to a module, dictionary, or a list of modules and/or dicts. Seeui-modules
for more details.
Authentication and security settings:
cookie_secret
: Used by RequestHandler.get_secure_cookie and .set_secure_cookie to sign cookies.login_url
: The authenticated decorator will redirect to this url if the user is not logged in. Can be further customized by overriding RequestHandler.get_login_urlxsrf_cookies
: If true,xsrf
will be enabled.twitter_consumer_key
,twitter_consumer_secret
,friendfeed_consumer_key
,friendfeed_consumer_secret
,google_consumer_key
,google_consumer_secret
,facebook_api_key
,facebook_secret
: Used in the tornado.auth module to authenticate to various APIs.
Template settings:
autoescape
: Controls automatic escaping for templates. May be set toNone
to disable escaping, or to the name of a function that all output should be passed through. Defaults to"xhtml_escape"
. Can be changed on a per-template basis with the{% autoescape %}
directive.template_path
: Directory containing template files. Can be further customized by overriding RequestHandler.get_template_pathtemplate_loader
: Assign to an instance of tornado.template.BaseLoader to customize template loading. If this setting is used thetemplate_path
andautoescape
settings are ignored. Can be further customized by overriding RequestHandler.create_template_loader.
Static file settings:
static_path
: Directory from which static files will be served.static_url_prefix
: Url prefix for static files, defaults to"/static/"
.static_handler_class
,static_handler_args
: May be set to use a different handler for static files instead of the default tornado.web.StaticFileHandler.static_handler_args
, if set, should be a dictionary of keyword arguments to be passed to the handler'sinitialize
method.
URLSpec
The URLSpec
class is also available under the name tornado.web.url
.
asynchronous
authenticated
addslash
removeslash
HTTPError
MissingArgumentError
UIModule
ErrorHandler
FallbackHandler
RedirectHandler
StaticFileHandler