Files
wordloop/backend/config.py
T
John bd7635986a Initial commit: WordLoop 单词学习应用
Vue 前端 + FastAPI 后端,含部署脚本与词典数据。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-04 14:30:53 -07:00

34 lines
848 B
Python

from functools import lru_cache
from urllib.parse import quote_plus
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
mysql_host: str = "localhost"
mysql_port: int = 3306
mysql_user: str = "boot"
mysql_password: str = "888888"
mysql_database: str = "wordloop"
@property
def database_url(self) -> str:
user = quote_plus(self.mysql_user)
password = quote_plus(self.mysql_password)
return (
f"mysql+pymysql://{user}:{password}"
f"@{self.mysql_host}:{self.mysql_port}/{self.mysql_database}"
"?charset=utf8mb4"
)
@lru_cache
def get_settings() -> Settings:
return Settings()