Skip to content
Myr

improved documentation for config.from_object (#1870)

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

authored by Jason Brazeal · committed by David Lord · parent 024fbe5 · Browse files · 2 files+9 added−3 removed
This commit

State

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

Diff stats

2 files+9 added−3 removed

  • other:+9 added−3 removed

2 files+9 added−3 removed

modified:docs/config.rst+1 added
308 unmodified lines
3092. Do not write code that needs the configuration at import time. If you310 limit yourself to request-only accesses to the configuration you can311 reconfigure the object later on as needed.312313.. _config-dev-prod:314315Development / Production316------------------------317
148 unmodified lines
modified:flask/config.py+8 added-3 removed
141 unmodified lines
142143 - a string: in this case the object with that name will be imported144 - an actual object reference: that object is used directly145146 Objects are usually either modules or classes.146 Objects are usually either modules or classes. :meth:`from_object`147 loads only the uppercase attributes of the module/class. A ``dict``148 object will not work with :meth:`from_object` because the keys of a149 ``dict`` are not attributes of the ``dict`` class.150148 Just the uppercase variables in that object are stored in the config.149 Example usage::151 Example of module-based configuration::152153 app.config.from_object('yourapplication.default_config')154 from yourapplication import default_config155 app.config.from_object(default_config)
2 unmodified lines
158 rather configuration defaults. The actual config should be loaded159 with :meth:`from_pyfile` and ideally from a location not within the160 package because the package might be installed system wide.161162 See :ref:`config-dev-prod` for an example of class-based configuration163 using :meth:`from_object`.164165 :param obj: an import name or object166 """167 if isinstance(obj, string_types):168 obj = import_string(obj)
95 unmodified lines