Skip to content

Commit 790d86a

Browse files
committed
Document all available application settings.
1 parent 5eb9821 commit 790d86a

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

tornado/web.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,13 @@ def get_template_namespace(self):
629629
return namespace
630630

631631
def create_template_loader(self, template_path):
632+
"""Returns a new template loader for the given path.
633+
634+
May be overridden by subclasses. By default returns a
635+
directory-based loader on the given path, using the
636+
``autoescape`` application setting. If a ``template_loader``
637+
application setting is supplied, uses that instead.
638+
"""
632639
settings = self.application.settings
633640
if "template_loader" in settings:
634641
return settings["template_loader"]
@@ -1219,18 +1226,6 @@ class Application(object):
12191226
and we will serve /favicon.ico and /robots.txt from the same directory.
12201227
A custom subclass of StaticFileHandler can be specified with the
12211228
static_handler_class setting.
1222-
1223-
.. attribute:: settings
1224-
1225-
Additional keyword arguments passed to the constructor are saved in the
1226-
`settings` dictionary, and are often referred to in documentation as
1227-
"application settings".
1228-
1229-
.. attribute:: debug
1230-
1231-
If `True` the application runs in debug mode, described in
1232-
:ref:`debug-mode`. This is an application setting in the `settings`
1233-
dictionary, so handlers can access it.
12341229
"""
12351230
def __init__(self, handlers=None, default_host="", transforms=None,
12361231
wsgi=False, **settings):

website/sphinx/overview.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ for more details. Check out the `Tornado Blog example application <https://githu
486486
complete example that uses authentication (and stores user data in a
487487
MySQL database).
488488

489+
.. _xsrf:
490+
489491
Cross-site request forgery protection
490492
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
491493

@@ -749,6 +751,8 @@ See the `tornado.locale`
749751
documentation for detailed information on the CSV format and other
750752
localization methods.
751753

754+
.. _ui-modules:
755+
752756
UI modules
753757
~~~~~~~~~~
754758

website/sphinx/web.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
.. automethod:: RequestHandler.async_callback
7878
.. automethod:: RequestHandler.check_xsrf_cookie
7979
.. automethod:: RequestHandler.compute_etag
80+
.. automethod:: RequestHandler.create_template_loader
8081
.. automethod:: RequestHandler.get_browser_locale
8182
.. automethod:: RequestHandler.get_current_user
8283
.. automethod:: RequestHandler.get_login_url
@@ -97,6 +98,76 @@
9798
.. autoclass:: Application
9899
:members:
99100

101+
.. attribute:: settings
102+
103+
Additional keyword arguments passed to the constructor are
104+
saved in the `settings` dictionary, and are often referred to
105+
in documentation as "application settings". Settings are
106+
used to customize various aspects of Tornado (although in
107+
some cases richer customization is possible by overriding
108+
methods in a subclass of `RequestHandler`). Some
109+
applications also like to use the `settings` dictionary as a
110+
way to make application-specific settings available to
111+
handlers without using global variables. Settings used in
112+
Tornado are described below.
113+
114+
General settings:
115+
116+
* ``debug``: If ``True`` the application runs in debug mode,
117+
described in :ref:`debug-mode`.
118+
* ``gzip``: If ``True``, responses in textual formats will be
119+
gzipped automatically.
120+
* ``log_function``: This function will be called at the end
121+
of every request to log the result (with one argument, the
122+
`RequestHandler` object). The default implementation
123+
writes to the `logging` module's root logger. May also be
124+
customized by overriding `Application.log_request`.
125+
* ``ui_modules`` and ``ui_methods``: May be set to a mapping
126+
of `UIModule` or UI methods to be made available to templates.
127+
May be set to a module, dictionary, or a list of modules
128+
and/or dicts. See :ref:`ui-modules` for more details.
129+
130+
Authentication and security settings:
131+
132+
* ``cookie_secret``: Used by `RequestHandler.get_secure_cookie`
133+
and `set_secure_cookie` to sign cookies.
134+
* ``login_url``: The `authenticated` decorator will redirect
135+
to this url if the user is not logged in. Can be further
136+
customized by overriding `RequestHandler.get_login_url`
137+
* ``xsrf_cookies``: If true, :ref:`xsrf` will be enabled.
138+
* ``twitter_consumer_key``, ``twitter_consumer_secret``,
139+
``friendfeed_consumer_key``, ``friendfeed_consumer_secret``,
140+
``google_consumer_key``, ``google_consumer_secret``,
141+
``facebook_api_key``, ``facebook_secret``: Used in the
142+
`tornado.auth` module to authenticate to various APIs.
143+
144+
Template settings:
145+
146+
* ``autoescape``: Controls automatic escaping for templates.
147+
May be set to ``None`` to disable escaping, or to the *name*
148+
of a function that all output should be passed through.
149+
Defaults to ``"xhtml_escape"``. Can be changed on a per-template
150+
basis with the ``{% autoescape %}`` directive.
151+
* ``template_path``: Directory containing template files. Can be
152+
further customized by overriding `RequestHandler.get_template_path`
153+
* ``template_loader``: Assign to an instance of
154+
`tornado.template.BaseLoader` to customize template loading.
155+
If this setting is used the ``template_path`` and ``autoescape``
156+
settings are ignored. Can be further customized by overriding
157+
`RequestHandler.create_template_loader`.
158+
159+
Static file settings:
160+
161+
* ``static_path``: Directory from which static files will be
162+
served.
163+
* ``static_url_prefix``: Url prefix for static files,
164+
defaults to ``"/static/"``.
165+
* ``static_handler_class``, ``static_handler_args``: May be set to
166+
use a different handler for static files instead of the default
167+
`tornado.web.StaticFileHandler`. ``static_handler_args``, if set,
168+
should be a dictionary of keyword arguments to be passed to the
169+
handler's ``initialize`` method.
170+
100171
.. autoclass:: URLSpec
101172

102173
The ``URLSpec`` class is also available under the name ``tornado.web.url``.

0 commit comments

Comments
 (0)