38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from pathlib import Path
|
|
from typing import Optional, Tuple, Type
|
|
|
|
from pydantic_settings import (
|
|
BaseSettings,
|
|
PydanticBaseSettingsSource,
|
|
SettingsConfigDict,
|
|
TomlConfigSettingsSource,
|
|
)
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings."""
|
|
|
|
# 应用配置
|
|
APP_NAME: str = "{{ cookiecutter.project_name }}"
|
|
DEBUG: bool = False
|
|
SECRET_KEY: str = "{{ cookiecutter.secret_key }}"
|
|
|
|
# 路径配置
|
|
BASE_DIR: Path = Path(__file__).parent.parent.parent
|
|
|
|
model_config = SettingsConfigDict(toml_file=BASE_DIR / "config.toml")
|
|
|
|
@classmethod
|
|
def settings_customise_sources(
|
|
cls,
|
|
settings_cls: Type[BaseSettings],
|
|
init_settings: PydanticBaseSettingsSource,
|
|
env_settings: PydanticBaseSettingsSource,
|
|
dotenv_settings: PydanticBaseSettingsSource,
|
|
file_secret_settings: PydanticBaseSettingsSource,
|
|
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
|
return (TomlConfigSettingsSource(settings_cls),)
|
|
|
|
|
|
# 创建全局设置实例
|
|
config = Settings()
|