Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pallets/flask/llms.txt
Use this file to discover all available pages before exploring further.
Config
TheConfig class works exactly like a dict but provides ways to fill it from files or special dictionaries.
Constructor
Path to which files are read relative from. When the config object is created by the application, this is the application’s
root_path.An optional dictionary of default values.
Example
Loading Configuration
from_pyfile()
Updates the values in the config from a Python file.The filename of the config. This can either be an absolute filename or a filename relative to the root path.
Set to
True if you want silent failure for missing files.True if the file was loaded successfully.
Example
from_object()
Updates the values from the given object.An import name or object. If it’s a string, the object with that name will be imported.
Example
from_envvar()
Loads a configuration from an environment variable pointing to a configuration file.Name of the environment variable.
Set to
True if you want silent failure for missing files.True if the file was loaded successfully.
Example
from_file()
Update the values in the config from a file that is loaded using theload parameter.
The path to the data file. This can be an absolute path or relative to the config root path.
A callable that takes a file handle and returns a mapping of loaded data from the file.
Ignore the file if it doesn’t exist.
Open the file in text or binary mode.
True if the file was loaded successfully.
Example
from_mapping()
Updates the config likeupdate() ignoring items with non-upper keys.
A mapping object to load config values from.
**kwargs
Additional keyword arguments to load as config values.
True.
Example
from_prefixed_env()
Load any environment variables that start withFLASK_, dropping the prefix from the env key for the config key.
Load env vars that start with this prefix, separated with an underscore (
_).Pass each string value to this function and use the returned value as the config value. If any error is raised it is ignored and the value remains a string.
__).
Returns True.
Example
Accessing Configuration
get_namespace()
Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix.A configuration namespace (prefix).
A flag indicating if the keys of the resulting dictionary should be lowercase.
A flag indicating if the keys of the resulting dictionary should not include the namespace.
Example
Configuration Best Practices
Development vs Production
Instance Folder Configuration
Environment Variables
Common Configuration Keys
| Key | Description | Default |
|---|---|---|
DEBUG | Enable debug mode | False |
TESTING | Enable testing mode | False |
SECRET_KEY | Secret key for sessions | None |
SESSION_COOKIE_NAME | Name of the session cookie | 'session' |
SESSION_COOKIE_HTTPONLY | HttpOnly flag for session cookie | True |
SESSION_COOKIE_SECURE | Secure flag for session cookie | False |
PERMANENT_SESSION_LIFETIME | Session lifetime as timedelta | timedelta(days=31) |
MAX_CONTENT_LENGTH | Maximum request content length | None |
SEND_FILE_MAX_AGE_DEFAULT | Max age for send_file cache | None |
TRAP_HTTP_EXCEPTIONS | Trap HTTP exceptions | False |
TEMPLATES_AUTO_RELOAD | Auto-reload templates | None (based on DEBUG) |
PREFERRED_URL_SCHEME | URL scheme for url_for | 'http' |
SERVER_NAME | Server name and port | None |
APPLICATION_ROOT | Application root path | '/' |
