Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé
Module « flask »

Classe « Config »

Informations générales

Héritage

builtins.object
    builtins.dict
        Config

Définition

class Config(builtins.dict):

help(Config)

Works exactly like a dict but provides ways to fill it from files
or special dictionaries.  There are two common patterns to populate the
config.

Either you can fill the config from a config file::

    app.config.from_pyfile('yourconfig.cfg')

Or alternatively you can define the configuration options in the
module that calls :meth:`from_object` or provide an import path to
a module that should be loaded.  It is also possible to tell it to
use the same module and with that provide the configuration values
just before the call::

    DEBUG = True
    SECRET_KEY = 'development key'
    app.config.from_object(__name__)

In both cases (loading from any Python file or loading from modules),
only uppercase keys are added to the config.  This makes it possible to use
lowercase values in the config file for temporary values that are not added
to the config or to define the config keys in the same file that implements
the application.

Probably the most interesting way to load configurations is from an
environment variable pointing to a file::

    app.config.from_envvar('YOURAPPLICATION_SETTINGS')

In this case before launching the application you have to set this
environment variable to the file you want to use.  On Linux and OS X
use the export statement::

    export YOURAPPLICATION_SETTINGS='/path/to/config/file'

On windows use `set` instead.

:param root_path: path to which files are read relative from.  When the
                  config object is created by the application, this is
                  the application's :attr:`~flask.Flask.root_path`.
:param defaults: an optional dictionary of default values

Constructeur(s)

Signature du constructeur Description
__init__(self, root_path: 'str | os.PathLike[str]', defaults: 'dict[str, t.Any] | None' = None) -> 'None'

Liste des opérateurs

Opérateurs hérités de la classe dict

__contains__, __delitem__, __eq__, __ge__, __getitem__, __gt__, __ior__, __le__, __lt__, __ne__, __or__, __ror__, __setitem__

Liste des opérateurs

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__class_getitem__(object) See PEP 585 [extrait de __class_getitem__.__doc__]
__repr__(self) -> 'str'
from_envvar(self, variable_name: 'str', silent: 'bool' = False) -> 'bool' Loads a configuration from an environment variable pointing to [extrait de from_envvar.__doc__]
from_file(self, filename: 'str | os.PathLike[str]', load: 't.Callable[[t.IO[t.Any]], t.Mapping[str, t.Any]]', silent: 'bool' = False, text: 'bool' = True) -> 'bool' Update the values in the config from a file that is loaded [extrait de from_file.__doc__]
from_mapping(self, mapping: 't.Mapping[str, t.Any] | None' = None, **kwargs: 't.Any') -> 'bool' Updates the config like :meth:`update` ignoring items with [extrait de from_mapping.__doc__]
from_object(self, obj: 'object | str') -> 'None' Updates the values from the given object. An object can be of one [extrait de from_object.__doc__]
from_prefixed_env(self, prefix: 'str' = 'FLASK', *, loads: 't.Callable[[str], t.Any]' = <function loads at 0x0000020DBA0FA0C0>) -> 'bool' Load any environment variables that start with ``FLASK_``, [extrait de from_prefixed_env.__doc__]
from_pyfile(self, filename: 'str | os.PathLike[str]', silent: 'bool' = False) -> 'bool' Updates the values in the config from a Python file. This function [extrait de from_pyfile.__doc__]
fromkeys(iterable, value=None) Create a new dictionary with keys from iterable and values set to value. [extrait de fromkeys.__doc__]
get_namespace(self, namespace: 'str', lowercase: 'bool' = True, trim_namespace: 'bool' = True) -> 'dict[str, t.Any]' Returns a dictionary containing a subset of configuration options [extrait de get_namespace.__doc__]

Méthodes héritées de la classe dict

__getattribute__, __init_subclass__, __iter__, __len__, __reversed__, __sizeof__, __subclasshook__, clear, copy, get, items, keys, pop, popitem, setdefault, update, values

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __init_subclass__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé