Skip to content
Myr

Merge branch 'master' of github.com:mitsuhiko/flask

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

authored by Armin Ronacher · committed by Armin Ronacher · parents a5da2c9, 1bca65d · Browse files · 2 files+21 added−19 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+21 added−19 removed

  • other:+21 added−19 removed

2 files+21 added−19 removed

modified:docs/deploying/uwsgi.rst+1 added-1 removed
34 unmodified lines
35Or, if you prefer:3637.. sourcecode:: text3839 $ uwsgi -s /tmp/uwsgi.sock myapp:app39 $ uwsgi -s /tmp/uwsgi.sock -w myapp:app4041Configuring nginx42-----------------43
25 unmodified lines
modified:docs/config.rst+20 added-18 removed
3 unmodified lines
4======================56.. versionadded:: 0.378Applications need some kind of configuration. There are different things9you might want to change like toggling debug mode, the secret key, and a10lot of very similar things.8Applications need some kind of configuration. There are different settings9you might want to change depending on the application environment like10toggling the debug mode, setting the secret key, and other such11environment-specific things.1213The way Flask is designed usually requires the configuration to be14available when the application starts up. You can hardcode the15configuration in the code, which for many small applications is not
15 unmodified lines
31 app = Flask(__name__)32 app.config['DEBUG'] = True3334Certain configuration values are also forwarded to the34:attr:`~flask.Flask` object so that you can read and write them from35there::35:attr:`~flask.Flask` object so you can read and write them from there::3637 app.debug = True3839To update multiple keys at once you can use the :meth:`dict.update`
106 unmodified lines
146147Configuring from Files148----------------------149150Configuration becomes more useful if you can configure from a file, and151ideally that file would be outside of the actual application package so that152you can install the package with distribute (:ref:`distribute-deployment`)153and still modify that file afterwards.150Configuration becomes more useful if you can store it in a separate file,151ideally located outside the actual application package. This makes152packaging and distributing your application possible via various package153handling tools (:ref:`distribute-deployment`) and finally modifying the154configuration file afterwards.155156So a common pattern is this::157158 app = Flask(__name__)
19 unmodified lines
178The configuration files themselves are actual Python files. Only values179in uppercase are actually stored in the config object later on. So make180sure to use uppercase letters for your config keys.181181Here is an example configuration file::182Here is an example of a configuration file::183184 # Example configuration185 DEBUG = False186 SECRET_KEY = '?\xbf,\xb4\x8d\xa3"<\x9c\xb0@\x0f5\xab,w\xee\x8d$0\x13\x8b83'187186Make sure to load the configuration very early on so that extensions have188Make sure to load the configuration very early on, so that extensions have189the ability to access the configuration when starting up. There are other190methods on the config object as well to load from individual files. For a191complete reference, read the :class:`~flask.Config` object's192documentation.
2 unmodified lines
195Configuration Best Practices196----------------------------197198The downside with the approach mentioned earlier is that it makes testing197a little harder. There is no one 100% solution for this problem in198general, but there are a couple of things you can do to improve that199experience:199a little harder. There is no single 100% solution for this problem in200general, but there are a couple of things you can keep in mind to improve201that experience:2022031. create your application in a function and register blueprints on it.204 That way you can create multiple instances of your application with205 different configurations attached which makes unittesting a lot
6 unmodified lines
212213Development / Production214------------------------215214Most applications need more than one configuration. There will at least215be a separate configuration for a production server and one used during216development. The easiest way to handle this is to use a default217configuration that is always loaded and part of version control, and a216Most applications need more than one configuration. There should be at217least separate configurations for the production server and the one used218during development. The easiest way to handle this is to use a default219configuration that is always loaded and part of the version control, and a220separate configuration that overrides the values as necessary as mentioned221in the example above::222223 app = Flask(__name__)
128 unmodified lines