config.py 711 字节
Newer Older
1
import os
2
import json
3
from pathlib import Path
4
from dotenv import load_dotenv
5

6
# Load the environment variables from .env file
7 8 9 10 11
path = Path(__file__).parent / ".env"
if path.exists():
    load_dotenv()
else:
    raise IOError(".env file not found")
12

13

14
class Config:
15 16
    base_path = Path(__file__).resolve().parent.parent.parent
    db_path = base_path / "data" / "chinook.db"
17 18

    SECRET_KEY = os.getenv("SECRET_KEY")
19
    SQLALCHEMY_DATABASE_URI = f"sqlite:///{str(db_path)}"
20 21 22
    SQLALCHEMY_TRACK_MODIFICATIONS = json.loads(
        os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS").lower()
    )
23 24
    SQLALCHEMY_ECHO = json.loads(os.getenv("SQLALCHEMY_ECHO").lower())
    DEBUG = json.loads(os.getenv("DEBUG").lower())