From d88c08e56f7398206596129036b8f101be11cba0 Mon Sep 17 00:00:00 2001 From: Jason Brazeal Date: Thu, 2 Jun 2016 15:40:59 -0700 Subject: [PATCH] improved documentation for config.from_object (#1870) --- docs/config.rst | 1 + flask/config.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 3039b3ea..4958d471 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -310,6 +310,7 @@ that experience: limit yourself to request-only accesses to the configuration you can reconfigure the object later on as needed. +.. _config-dev-prod: Development / Production ------------------------ diff --git a/flask/config.py b/flask/config.py index 426a23a2..36e8a123 100644 --- a/flask/config.py +++ b/flask/config.py @@ -143,10 +143,12 @@ class Config(dict): - a string: in this case the object with that name will be imported - an actual object reference: that object is used directly - Objects are usually either modules or classes. + Objects are usually either modules or classes. :meth:`from_object` + loads only the uppercase attributes of the module/class. A ``dict`` + object will not work with :meth:`from_object` because the keys of a + ``dict`` are not attributes of the ``dict`` class. - Just the uppercase variables in that object are stored in the config. - Example usage:: + Example of module-based configuration:: app.config.from_object('yourapplication.default_config') from yourapplication import default_config @@ -157,6 +159,9 @@ class Config(dict): with :meth:`from_pyfile` and ideally from a location not within the package because the package might be installed system wide. + See :ref:`config-dev-prod` for an example of class-based configuration + using :meth:`from_object`. + :param obj: an import name or object """ if isinstance(obj, string_types):