tmpl-fastapi/app/common.py

33 lines
612 B
Python

import secrets
from pathlib import Path
from fastapi.templating import Jinja2Templates
from pydantic import BaseSettings
# Directories
file_dir = Path(__file__).parent
templates_dir = str(
file_dir.parent / 'templates'
)
static_dir = str(
file_dir.parent / 'static'
)
# Main configuration
class Settings(BaseSettings):
debug: bool = False
session_key: str = secrets.token_hex(32)
csrf_key: str = secrets.token_hex(32)
app_host: str = '127.0.0.1'
app_port: int = 8000
settings = Settings()
# Jinja templates handler
templates = Jinja2Templates(
directory=templates_dir,
)