· 7 years ago · May 13, 2018, 04:02 AM
1app = Flask(__name__)
2app.config.from_object('yourapplication.Config')
3
4class Config(object):
5 DEBUG = True
6 TESTING = False
7 DB_USER = os.getenv("DB_USER", "db_user")
8 DB_PASSWORD = os.getenv("DB_PASSWORD", "db_password")
9 DB_HOST = os.getenv("DB_HOST", "localhost") # 127.0.0.1"
10 DB_PORT = os.getenv("DB_PORT", "5555")
11 DB_SCHEMA = "my_schema"
12 DB_DATABASE_NAME = "my_database"
13 SQLALCHEMY_DATABASE_URI = "postgresql://{}:{}@{}:{}/{}".format(
14 DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE_NAME)
15 SQLALCHEMY_TRACK_MODIFICATIONS = False
16
17my_flask_app cmd1 arg1 arg2
18
19DEBUG=true DB_PORT=1234 my_flask_app cmd1 arg1 arg2
20
21class BaseConfig:
22 DEBUG = False
23 TESTING = False
24 SECRET_KEY = os.getenv('SECRET_KEY', 'a default secret key')
25 ...
26
27class DevelopmentConfig(BaseConfig):
28 DEBUG = True
29 ...
30
31
32class TestingConfig(BaseConfig):
33 TESTING = True
34 ...
35
36
37class ProductionConfig(BaseConfig):
38 ...
39
40app = Flask(__name__)
41app_settings = os.getenv(
42 'APP_SETTINGS',
43 'app.config.DevelopmentConfig'
44)
45app.config.from_object(app_settings)
46
47> APP_SETTINGS=app.config.TestingConfig my_flask_app cmd1 arg1 arg2