July 2017
Beginner to intermediate
340 pages
7h 43m
English
When building applications, you will need to expose options to run them, like the information to connect to a database or any other variable that is specific to a deployment.
Flask uses a mechanism similar to Django in its configuration approach. The Flask object comes with an object called config, which contains some built-in variables, and which can be updated when you start your Flask app via your configuration objects.
For example, you can define a Config class in a prod_settings.py file as follows:
class Config: DEBUG = False SQLURI = 'postgres://tarek:xxx@localhost/db'
And then, load it from your app object using app.config.from_object :
>>> from flask import Flask >>> app = Flask(__name__) >>> app.config.from_object('prod_settings.Config') ...