forked from orbit-oss/flask
Support loading configuration from text files
TOML is a very popular format now, and is taking hold in the Python
ecosystem via pyproject.toml (among others). This allows toml config
files via,
app.config.from_file("config.toml", toml.loads)
it also allows for any other file format whereby there is a loader
that takes a string and returns a mapping.
This commit is contained in:
parent
7df10cd8e0
commit
829aa65e64
3 changed files with 59 additions and 19 deletions
|
|
@ -393,8 +393,8 @@ The following configuration values are used internally by Flask:
|
|||
Added :data:`MAX_COOKIE_SIZE` to control a warning from Werkzeug.
|
||||
|
||||
|
||||
Configuring from Files
|
||||
----------------------
|
||||
Configuring from Python Files
|
||||
-----------------------------
|
||||
|
||||
Configuration becomes more useful if you can store it in a separate file,
|
||||
ideally located outside the actual application package. This makes
|
||||
|
|
@ -440,6 +440,20 @@ methods on the config object as well to load from individual files. For a
|
|||
complete reference, read the :class:`~flask.Config` object's
|
||||
documentation.
|
||||
|
||||
Configuring from files
|
||||
----------------------
|
||||
|
||||
It is also possible to load configure from a flat file in a format of
|
||||
your choice, for example to load from a TOML (or JSON) formatted
|
||||
file::
|
||||
|
||||
import json
|
||||
import toml
|
||||
|
||||
app.config.from_file("config.toml", load=toml.load)
|
||||
# Alternatively, if you prefer JSON
|
||||
app.config.from_file("config.json", load=json.load)
|
||||
|
||||
|
||||
Configuring from Environment Variables
|
||||
--------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue