Skip to content
Myr

reformat config from table to linkable sections

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 399ac3c · Browse files · 1 file+235 added−166 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+235 added−166 removed

  • other:+235 added−166 removed

1 file+235 added−166 removed

modified:docs/config.rst+235 added-166 removed
1 unmodified line
23Configuration Handling4======================56.. versionadded:: 0.376Applications need some kind of configuration. There are different settings7you might want to change depending on the application environment like8toggling the debug mode, setting the secret key, and other such9environment-specific things.
41 unmodified lines
51 $ export FLASK_DEBUG=152 $ flask run5354 (On Windows you need to use ``set`` instead of ``export``).57 58 ``app.debug`` and ``app.config['DEBUG']`` are not compatible with 5556 ``app.debug`` and ``app.config['DEBUG']`` are not compatible with57   the :command:`flask` script. They only worked when using ``Flask.run()``58 method.61 5960Builtin Configuration Values61----------------------------6263The following configuration values are used internally by Flask:6467.. tabularcolumns:: |p{6.5cm}|p{8.5cm}|65.. py:data:: DEBUG6669================================= =========================================70``DEBUG`` enable/disable debug mode when using 71 ``Flask.run()`` method to start server72``TESTING`` enable/disable testing mode73``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the74 propagation of exceptions. If not set or75 explicitly set to ``None`` this is76 implicitly true if either ``TESTING`` or77 ``DEBUG`` is true.78``PRESERVE_CONTEXT_ON_EXCEPTION`` By default if the application is in79 debug mode the request context is not80 popped on exceptions to enable debuggers81 to introspect the data. This can be82 disabled by this key. You can also use83 this setting to force-enable it for non84 debug execution which might be useful to85 debug production applications (but also86 very risky).87``SECRET_KEY`` the secret key88``SESSION_COOKIE_NAME`` the name of the session cookie89``SESSION_COOKIE_DOMAIN`` the domain for the session cookie. If90 this is not set, the cookie will be91 valid for all subdomains of92 ``SERVER_NAME``.93``SESSION_COOKIE_PATH`` the path for the session cookie. If94 this is not set the cookie will be valid95 for all of ``APPLICATION_ROOT`` or if96 that is not set for ``'/'``.97``SESSION_COOKIE_HTTPONLY`` controls if the cookie should be set98 with the httponly flag. Defaults to99 ``True``.100``SESSION_COOKIE_SECURE`` controls if the cookie should be set101 with the secure flag. Defaults to102 ``False``.103``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as104 :class:`datetime.timedelta` object.105 Starting with Flask 0.8 this can also be106 an integer representing seconds.107``SESSION_REFRESH_EACH_REQUEST`` this flag controls how permanent108 sessions are refreshed. If set to ``True``109 (which is the default) then the cookie110 is refreshed each request which111 automatically bumps the lifetime. If112 set to ``False`` a `set-cookie` header is113 only sent if the session is modified.114 Non permanent sessions are not affected115 by this.116``USE_X_SENDFILE`` enable/disable x-sendfile117``LOGGER_NAME`` the name of the logger118``LOGGER_HANDLER_POLICY`` the policy of the default logging119 handler. The default is ``'always'``120 which means that the default logging121 handler is always active. ``'debug'``122 will only activate logging in debug123 mode, ``'production'`` will only log in124 production and ``'never'`` disables it125 entirely.126``SERVER_NAME`` the name and port number of the server.127 Required for subdomain support (e.g.:128 ``'myapp.dev:5000'``) Note that129 localhost does not support subdomains so130 setting this to “localhost” does not131 help. Setting a ``SERVER_NAME`` also132 by default enables URL generation133 without a request context but with an134 application context.135``APPLICATION_ROOT`` The path value used for the session136 cookie if ``SESSION_COOKIE_PATH`` isn't137 set. If it's also ``None`` ``'/'`` is used.138 Note that to actually serve your Flask139 app under a subpath you need to tell140 your WSGI container the ``SCRIPT_NAME``141 WSGI environment variable.142``MAX_CONTENT_LENGTH`` If set to a value in bytes, Flask will143 reject incoming requests with a144 content length greater than this by145 returning a 413 status code.146``SEND_FILE_MAX_AGE_DEFAULT`` Default cache control max age to use with147 :meth:`~flask.Flask.send_static_file` (the148 default static file handler) and149 :func:`~flask.send_file`, as150 :class:`datetime.timedelta` or as seconds.151 Override this value on a per-file152 basis using the153 :meth:`~flask.Flask.get_send_file_max_age`154 hook on :class:`~flask.Flask` or155 :class:`~flask.Blueprint`,156 respectively. Defaults to 43200 (12 hours).157``TRAP_HTTP_EXCEPTIONS`` If this is set to ``True`` Flask will158 not execute the error handlers of HTTP159 exceptions but instead treat the160 exception like any other and bubble it161 through the exception stack. This is162 helpful for hairy debugging situations163 where you have to find out where an HTTP164 exception is coming from.165``TRAP_BAD_REQUEST_ERRORS`` Werkzeug's internal data structures that166 deal with request specific data will167 raise special key errors that are also168 bad request exceptions. Likewise many169 operations can implicitly fail with a170 BadRequest exception for consistency.171 Since it's nice for debugging to know172 why exactly it failed this flag can be173 used to debug those situations. If this174 config is set to ``True`` you will get175 a regular traceback instead.176``PREFERRED_URL_SCHEME`` The URL scheme that should be used for177 URL generation if no URL scheme is178 available. This defaults to ``http``.179``JSON_AS_ASCII`` By default Flask serialize object to180 ascii-encoded JSON. If this is set to181 ``False`` Flask will not encode to ASCII182 and output strings as-is and return183 unicode strings. ``jsonify`` will184 automatically encode it in ``utf-8``185 then for transport for instance.186``JSON_SORT_KEYS`` By default Flask will serialize JSON187 objects in a way that the keys are188 ordered. This is done in order to189 ensure that independent of the hash seed190 of the dictionary the return value will191 be consistent to not trash external HTTP192 caches. You can override the default193 behavior by changing this variable.194 This is not recommended but might give195 you a performance improvement on the196 cost of cacheability.197``JSONIFY_PRETTYPRINT_REGULAR`` If this is set to ``True`` or the Flask app198 is running in debug mode, jsonify responses199 will be pretty printed.200``JSONIFY_MIMETYPE`` MIME type used for jsonify responses.201``TEMPLATES_AUTO_RELOAD`` Whether to check for modifications of202 the template source and reload it203 automatically. By default the value is204 ``None`` which means that Flask checks205 original file only in debug mode.206``EXPLAIN_TEMPLATE_LOADING`` If this is enabled then every attempt to207 load a template will write an info208 message to the logger explaining the209 attempts to locate the template. This210 can be useful to figure out why211 templates cannot be found or wrong212 templates appear to be loaded.213================================= =========================================67 Enable debug mode. When using the development server with ``flask run`` or68 ``app.run``, an interactive debugger will be shown for unhanlded69 exceptions, and the server will be reloaded when code changes.70215.. admonition:: More on ``SERVER_NAME``71 **Do not enable debug mode in production.**72217 The ``SERVER_NAME`` key is used for the subdomain support. Because218 Flask cannot guess the subdomain part without the knowledge of the219 actual server name, this is required if you want to work with220 subdomains. This is also used for the session cookie.73 Default: ``False``74222 Please keep in mind that not only Flask has the problem of not knowing223 what subdomains are, your web browser does as well. Most modern web224 browsers will not allow cross-subdomain cookies to be set on a225 server name without dots in it. So if your server name is226 ``'localhost'`` you will not be able to set a cookie for227 ``'localhost'`` and every subdomain of it. Please choose a different228 server name in that case, like ``'myapplication.local'`` and add229 this name + the subdomains you want to use into your host config230 or setup a local `bind`_.75.. py:data:: TESTING76232.. _bind: https://www.isc.org/downloads/bind/77 Enable testing mode. Exceptions are propagated rather than handled by the78 the app's error handlers. Extensions may also change their behavior to79 facilitate easier testing. You should enable this in your own tests.8081 Default: ``False``8283.. py:data:: PROPAGATE_EXCEPTIONS8485 Exceptions are re-raised rather than being handled by the app's error86 handlers. If not set, this is implicitly true if ``TESTING`` or ``DEBUG``87 is enabled.8889 Default: ``None``9091.. py:data:: PRESERVE_CONTEXT_ON_EXCEPTION9293 Don't pop the request context when an exception occurs. If not set, this94 is true if ``DEBUG`` is true. This allows debuggers to introspect the95 request data on errors, and should normally not need to be set directly.9697 Default: ``None``9899.. py:data:: TRAP_HTTP_EXCEPTIONS100101 If there is no handler for an ``HTTPException``-type exception, re-raise it102 to be handled by the interactive debugger instead of returning it as a103 simple error response.104105 Default: ``False``106107.. py:data:: TRAP_BAD_REQUEST_ERRORS``108109 Trying to access a key that doesn't exist from request dicts like ``args``110 and ``form`` will return a 400 Bad Request error page. Enable this to treat111 the error as an unhandled exception instead so that you get the interactive112 debugger. This is a more specific version of ``TRAP_HTTP_EXCEPTIONS``.113114 Default: ``False``115116.. py:data:: SECRET_KEY117118 A secret key that will be used for securely signing the session cookie119 and can be used for any other security related needs by extensions or your120 application. It should be a long random string of bytes, although unicode121 is accepted too. For example, copy the output of this to your config::122123 python -c 'import os; print(os.urandom(32))'124125 **Do not reveal the secret key when posting questions or committing code.**126127 Default: ``None``128129.. py:data:: SESSION_COOKIE_NAME130131 The name of the session cookie. Can be changed in case you already have a132 cookie with the same name.133134 Default: ``'session'``135136.. py:data:: SESSION_COOKIE_DOMAIN137138 The domain match rule that the session cookie will be valid for. If not139 set, the cookie will be valid for all subdomains of ``SERVER_NAME``. If140 ``False``, the cookie's domain will not be set.141142 Default: ``None``143144.. py:data:: SESSION_COOKIE_PATH145146 The path that the session cookie will be valid for. If not set, the cookie147 will be valid underneath ``APPLICATION_ROOT`` or ``/`` if that is not set.148149 Default: ``None``150151.. py:data:: SESSION_COOKIE_HTTPONLY152153 Browsers will not allow JavaScript access to cookies marked as "HTTP only"154 for security.155156 Default: ``True``157158.. py:data:: SESSION_COOKIE_SECURE159160 Browsers will only send cookies with requests over HTTPS if the cookie is161 marked "secure". The application must be served over HTTPS for this to make162 sense.163164 Default: ``False``165166.. py:data:: SESSION_COOKIE_LIFETIME167168 If ``session.permanent`` is true, the cookie's max age will be set to this169 number of seconds. Can either be a :class:`datetime.timedelta` or an170 ``int``.171172 Default: ``timedelta(days=31)`` (``2678400`` seconds)173174.. py:data:: SESSION_REFRESH_EACH_REQUEST175176 Control whether the cookie is sent with every response when177 ``session.permanent`` is true. Sending the cookie every time (the default)178 can more reliably keep the session from expiring, but uses more bandwidth.179 Non-permanent sessions are not affected.180181 Default: ``True``182183.. py:data:: USE_X_SENDFILE184185 When serving files, set the ``X-Sendfile`` header instead of serving the186 data with Flask. Some web servers, such as Apache, recognize this and serve187 the data more efficiently. This only makes sense when using such a server.188189 Default: ``False``190191.. py:data:: SEND_FILE_MAX_AGE192193 When serving files, set the cache control max age to this number of194 seconds. Can either be a :class:`datetime.timedelta` or an ``int``.195 Override this value on a per-file basis using196 :meth:`~flask.Flask.get_send_file_max_age` on the application or blueprint.197198 Default: ``timedelta(hours=12)`` (``43200`` seconds)199200.. py:data:: LOGGER_NAME201202 The name of the logger that the Flask application sets up. If not set,203 it will take the import name passed to ``Flask.__init__``.204205 Default: ``None``206207.. py:data:: LOGGER_HANDLER_POLICY208209 When to activate the application's logger handler. ``'always'`` always210 enables it, ``'debug'`` only activates it in debug mode, ``'production'``211 only activates it when not in debug mode, and ``'never'`` never enables it.212213 Default: ``'always'``214215.. py:data:: SERVER_NAME216217 Inform the application what host and port it is bound to. Required for218 subdomain route matching support.219220 If set, will be used for the session cookie domain if221 ``SESSION_COOKIE_DOMAIN`` is not set. Modern web browsers will not allow222 setting cookies for domains without a dot. To use a domain locally,223 add any names that should route to the app to your ``hosts`` file. ::224225 127.0.0.1 localhost.dev226227 If set, ``url_for`` can generate external URLs with only an application228 context instead of a request context.229230 Default: ``None``231232.. py:data:: APPLICATION_ROOT233234 Inform the application what path it is mounted under by the application /235 web server.236237 Will be used for the session cookie path if ``SESSION_COOKIE_PATH`` is not238 set.239240 Default: ``'/'``241242.. py:data:: PREFERRED_URL_SCHEME243244 Use this scheme for generating external URLs when not in a request context.245246 Default: ``'http'``247248.. py:data:: MAX_CONTENT_LENGTH249250 Don't read more than this many bytes from the incoming request data. If not251 set and the request does not specify a ``CONTENT_LENGTH``, no data will be252 read for security.253254 Default: ``None``255256.. py:data:: JSON_AS_ASCII257258 Serialize objects to ASCII-encoded JSON. If this is disabled, the JSON259 will be returned as a Unicode string, or encoded as ``UTF-8`` by260 ``jsonify``. This has security implications when rendering the JSON in261 to JavaScript in templates, and should typically remain enabled.262263 Default: ``True``264265.. py:data:: JSON_SORT_KEYS266267 Sort the keys of JSON objects alphabetically. This is useful for caching268 because it ensures the data is serialized the same way no matter what269 Python's hash seed is. While not recommended, you can disable this for a270 possible performance improvement at the cost of caching.271272 Default: ``True``273274.. py:data:: JSONIFY_PRETTYPRINT_REGULAR275276 ``jsonify`` responses will be output with newlines, spaces, and indentation277 for easier reading by humans. Always enabled in debug mode.278279 Default: ``False``280281.. py:data:: JSONIFY_MIMETYPE282283 The mimetype of ``jsonify`` responses.284285 Default: ``'application/json'``286287.. py:data:: TEMPLATES_AUTO_RELOAD288289 Reload templates when they are changed. If not set, it will be enabled in290 debug mode.291292 Default: ``None``293294.. py:data:: EXPLAIN_TEMPLATE_LOADING295296 Log debugging information tracing how a template file was loaded. This can297 be useful to figure out why a template was not loaded or the wrong file298 appears to be loaded.299300 Default: ``False``301302.. versionadded:: 0.4303 ``LOGGER_NAME``304305.. versionadded:: 0.5
238 unmodified lines
544545 # or via open_instance_resource:546 with app.open_instance_resource('application.cfg') as f:547 config = f.read()548