diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..5b64cd1 --- /dev/null +++ b/.env.dev @@ -0,0 +1,24 @@ +# 应用配置 +ALLOWED_ORIGINS = http://127.0.0.1:3000,http://localhost:3000 + +# 身份认证 +ACCESS_SECRET_KEY = a2f718e8313bf8efcb45ef7364d040c45800f34d10f65776eef0f6584677ecd0 + +# 数据库配置 +DB_USER = card_book +DB_PASSWORD = DFCPjk4rdkca6SPE +DB_HOST = 192.168.3.4 +DB_NAME = card_book + +# redis配置 +REDIS_PASSWORD = xingc +REDIS_HOST = 192.168.3.4 +REDIS_PORT = 6379 +REDIS_DB = 0 + +# 代理 +OVERSEAS_PROXY = 'http://127.0.0.1:7890' + +# 微信 +APPID = +APP_SECRET = \ No newline at end of file diff --git a/config.py b/config.py index ffb7d3c..2370499 100644 --- a/config.py +++ b/config.py @@ -11,12 +11,10 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): - model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8') - # 基础设置 NAME: str = 'card book' PREFIX: str = NAME.lower().replace(' ', '_') - ENVIRONMENT: str = 'development' + ENVIRONMENT: str = 'dev' BASE_DIR: str = os.path.dirname(os.path.abspath(__file__)) DEBUG: bool = True @@ -65,10 +63,12 @@ class Settings(BaseSettings): APPID: str = '' APP_SECRET: str = '' + model_config = SettingsConfigDict(env_file=F'.env.{ENVIRONMENT.lower()}', env_file_encoding='utf-8') + class ProductionSettings(Settings): # 基础设置 - ENVIRONMENT: str = 'production' + ENVIRONMENT: str = 'prod' DEBUG: bool = False # 身份认证 @@ -78,9 +78,6 @@ class ProductionSettings(Settings): class DevelopmentSettings(Settings): - # 应用配置 - ALLOWED_ORIGINS: str = 'http://127.0.0.1:3000,http://localhost:3000' - # 日志配置 LOG_LEVEL: int = logging.INFO @@ -98,10 +95,10 @@ class DevelopmentSettings(Settings): def get_settings(): - env = os.environ.get('ENVIRONMENT', 'development') - if env == 'development': + env = os.environ.get('ENVIRONMENT', 'dev') + if env == 'dev': return DevelopmentSettings() - elif env == 'production': + elif env == 'prod': return ProductionSettings() return Settings()