· 6 years ago · Jul 30, 2019, 02:12 PM
1import os
2basedir = os.path.abspath(os.path.dirname(__file__))
3
4#example to add additional configuration
5class Config:
6 SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
7 SQLALCHEMY_TRACK_MODIFICATIONS = False
8
9 @staticmethod
10 def init_app(app):
11 pass
12
13
14#example how to develop different database configuration for different stage
15class DevelopmentConfig(Config):
16 DEBUG = True
17 # my mysql connection is using username root with password root
18 # and using database blueprint
19 SQLALCHEMY_DATABASE_URI = 'mysql://root:root@localhost/blueprint'
20
21
22class TestingConfig(Config):
23 TESTING = True
24 SQLALCHEMY_DATABASE_URI = 'sqlite://'
25
26
27class ProductionConfig(Config):
28 SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
29
30
31config = {
32 'development': DevelopmentConfig,
33 'testing': TestingConfig,
34 'production': ProductionConfig,
35 'default': DevelopmentConfig
36}