first commit
This commit is contained in:
43
config/__init__.py
Normal file
43
config/__init__.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
配置管理模块
|
||||
根据环境变量自动选择对应的配置类
|
||||
"""
|
||||
import os
|
||||
from .base import Config
|
||||
from .development import DevelopmentConfig
|
||||
from .production import ProductionConfig
|
||||
from .testing import TestingConfig
|
||||
from .local import LocalConfig
|
||||
|
||||
# 配置映射字典
|
||||
config_map = {
|
||||
'development': DevelopmentConfig,
|
||||
'production': ProductionConfig,
|
||||
'testing': TestingConfig,
|
||||
'local': LocalConfig,
|
||||
'default': DevelopmentConfig
|
||||
}
|
||||
|
||||
def get_config():
|
||||
"""
|
||||
根据环境变量获取对应的配置类
|
||||
|
||||
环境变量: FLASK_ENV
|
||||
可选值: development, production, testing, local
|
||||
|
||||
Returns:
|
||||
Config类: 对应环境的配置类
|
||||
"""
|
||||
env = os.environ.get('FLASK_ENV', 'development')
|
||||
return config_map.get(env, config_map['default'])
|
||||
|
||||
# 导出配置类
|
||||
__all__ = [
|
||||
'Config',
|
||||
'DevelopmentConfig',
|
||||
'ProductionConfig',
|
||||
'TestingConfig',
|
||||
'LocalConfig',
|
||||
'get_config'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user