Merge pull request #304 from plaes/config-docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Improve configuration docs a bit
authored by Ron DuPlain · committed by Ron DuPlain · parents 45d963d, 713ced6 · Browse files · 1 file·+20 added−18 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+20 added−18 removed
- other:+20 added−18 removed
Provenance
- Commit
b209cd9- Tree
78e6504- Author
Ron DuPlain <ron.duplain@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent 1
45d963d- Parent 2
713ced6
1 file changed+20 added−18 removed
modified:docs/config.rst+20 added-18 removed
3 unmodified lines4 ======================5 6 .. versionadded:: 0.37 8-Applications need some kind of configuration. There are different things9-you might want to change like toggling debug mode, the secret key, and a10-lot of very similar things.8+Applications need some kind of configuration. There are different settings9+you might want to change depending on the application environment like10+toggling the debug mode, setting the secret key, and other such11+environment-specific things.12 13 The way Flask is designed usually requires the configuration to be14 available when the application starts up. You can hardcode the15 configuration in the code, which for many small applications is not15 unmodified lines31 app = Flask(__name__)32 app.config['DEBUG'] = True33 34 Certain configuration values are also forwarded to the34-:attr:`~flask.Flask` object so that you can read and write them from35-there::35+:attr:`~flask.Flask` object so you can read and write them from there::36 37 app.debug = True38 39 To update multiple keys at once you can use the :meth:`dict.update`98 unmodified lines138 139 Configuring from Files140 ----------------------141 142-Configuration becomes more useful if you can configure from a file, and143-ideally that file would be outside of the actual application package so that144-you can install the package with distribute (:ref:`distribute-deployment`)145-and still modify that file afterwards.142+Configuration becomes more useful if you can store it in a separate file,143+ideally located outside the actual application package. This makes144+packaging and distributing your application possible via various package145+handling tools (:ref:`distribute-deployment`) and finally modifying the146+configuration file afterwards.147 148 So a common pattern is this::149 150 app = Flask(__name__)19 unmodified lines170 The configuration files themselves are actual Python files. Only values171 in uppercase are actually stored in the config object later on. So make172 sure to use uppercase letters for your config keys.173 173-Here is an example configuration file::174+Here is an example of a configuration file::175 176+ # Example configuration177 DEBUG = False178 SECRET_KEY = '?\xbf,\xb4\x8d\xa3"<\x9c\xb0@\x0f5\xab,w\xee\x8d$0\x13\x8b83'179 178-Make sure to load the configuration very early on so that extensions have180+Make sure to load the configuration very early on, so that extensions have181 the ability to access the configuration when starting up. There are other182 methods on the config object as well to load from individual files. For a183 complete reference, read the :class:`~flask.Config` object's184 documentation.2 unmodified lines187 Configuration Best Practices188 ----------------------------189 190 The downside with the approach mentioned earlier is that it makes testing189-a little harder. There is no one 100% solution for this problem in190-general, but there are a couple of things you can do to improve that191-experience:191+a little harder. There is no single 100% solution for this problem in192+general, but there are a couple of things you can keep in mind to improve193+that experience:194 195 1. create your application in a function and register blueprints on it.196 That way you can create multiple instances of your application with197 different configurations attached which makes unittesting a lot6 unmodified lines204 205 Development / Production206 ------------------------207 206-Most applications need more than one configuration. There will at least207-be a separate configuration for a production server and one used during208-development. The easiest way to handle this is to use a default209-configuration that is always loaded and part of version control, and a208+Most applications need more than one configuration. There should be at209+least separate configurations for the production server and the one used210+during development. The easiest way to handle this is to use a default211+configuration that is always loaded and part of the version control, and a212 separate configuration that overrides the values as necessary as mentioned213 in the example above::214 215 app = Flask(__name__)128 unmodified lines