上QQ阅读APP看书,第一时间看更新
How to do it...
We can have a default setting base class, and other classes can inherit that base class and override or add deployment-specific configuration variables to it, as shown in the following example:
class BaseConfig(object): 'Base config class' SECRET_KEY = 'A random secret key' DEBUG = True TESTING = False NEW_CONFIG_VARIABLE = 'my value' class ProductionConfig(BaseConfig): 'Production specific config' DEBUG = False SECRET_KEY = open('/path/to/secret/file').read() class StagingConfig(BaseConfig): 'Staging specific config' DEBUG = True class DevelopmentConfig(BaseConfig): 'Development environment specific config' DEBUG = True TESTING = True SECRET_KEY = 'Another random secret key'
The secret key is stored in a separate file because, for security reasons, it should not be a part of your version-control system. This should be kept in the local filesystem on the machine itself, whether it is your personal machine or a server.