feat(config): 新增环境变量文件
This commit is contained in:
24
.env.dev
Normal file
24
.env.dev
Normal file
@@ -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 =
|
||||||
17
config.py
17
config.py
@@ -11,12 +11,10 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
|
|
||||||
|
|
||||||
# 基础设置
|
# 基础设置
|
||||||
NAME: str = 'card book'
|
NAME: str = 'card book'
|
||||||
PREFIX: str = NAME.lower().replace(' ', '_')
|
PREFIX: str = NAME.lower().replace(' ', '_')
|
||||||
ENVIRONMENT: str = 'development'
|
ENVIRONMENT: str = 'dev'
|
||||||
BASE_DIR: str = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR: str = os.path.dirname(os.path.abspath(__file__))
|
||||||
DEBUG: bool = True
|
DEBUG: bool = True
|
||||||
|
|
||||||
@@ -65,10 +63,12 @@ class Settings(BaseSettings):
|
|||||||
APPID: str = '<KEY>'
|
APPID: str = '<KEY>'
|
||||||
APP_SECRET: str = '<KEY>'
|
APP_SECRET: str = '<KEY>'
|
||||||
|
|
||||||
|
model_config = SettingsConfigDict(env_file=F'.env.{ENVIRONMENT.lower()}', env_file_encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
class ProductionSettings(Settings):
|
class ProductionSettings(Settings):
|
||||||
# 基础设置
|
# 基础设置
|
||||||
ENVIRONMENT: str = 'production'
|
ENVIRONMENT: str = 'prod'
|
||||||
DEBUG: bool = False
|
DEBUG: bool = False
|
||||||
|
|
||||||
# 身份认证
|
# 身份认证
|
||||||
@@ -78,9 +78,6 @@ class ProductionSettings(Settings):
|
|||||||
|
|
||||||
|
|
||||||
class DevelopmentSettings(Settings):
|
class DevelopmentSettings(Settings):
|
||||||
# 应用配置
|
|
||||||
ALLOWED_ORIGINS: str = 'http://127.0.0.1:3000,http://localhost:3000'
|
|
||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
LOG_LEVEL: int = logging.INFO
|
LOG_LEVEL: int = logging.INFO
|
||||||
|
|
||||||
@@ -98,10 +95,10 @@ class DevelopmentSettings(Settings):
|
|||||||
|
|
||||||
|
|
||||||
def get_settings():
|
def get_settings():
|
||||||
env = os.environ.get('ENVIRONMENT', 'development')
|
env = os.environ.get('ENVIRONMENT', 'dev')
|
||||||
if env == 'development':
|
if env == 'dev':
|
||||||
return DevelopmentSettings()
|
return DevelopmentSettings()
|
||||||
elif env == 'production':
|
elif env == 'prod':
|
||||||
return ProductionSettings()
|
return ProductionSettings()
|
||||||
|
|
||||||
return Settings()
|
return Settings()
|
||||||
|
|||||||
Reference in New Issue
Block a user