diff --git a/app/common.py b/app/common.py index fd32614..8d048ae 100644 --- a/app/common.py +++ b/app/common.py @@ -5,20 +5,21 @@ from fastapi.templating import Jinja2Templates from pydantic import BaseSettings -file_dir = Path(__file__).parent - class Settings(BaseSettings): secret_key: str = secrets.token_hex(32) - templates_dir: str = str( - file_dir.parent / 'templates' - ) - static_dir: str = str( - file_dir.parent / 'static' - ) settings = Settings() -templates = Jinja2Templates( - directory=settings.templates_dir, +file_dir = Path(__file__).parent +templates_dir = str( + file_dir.parent / 'templates' +) +static_dir = str( + file_dir.parent / 'static' +) + + +templates = Jinja2Templates( + directory=templates_dir, ) diff --git a/app/errors.py b/app/errors.py index 402ba91..3381368 100644 --- a/app/errors.py +++ b/app/errors.py @@ -7,7 +7,7 @@ from fastapi import HTTPException from . import paths from . import respond -from .common import settings +from . import common # Add other HTTP error codes codes = [404, 500] @@ -30,11 +30,7 @@ class ErrorsPaths(paths.Paths): code (int): HTTP error code """ - tmpl_dir = ( - Path(__file__).parent / - settings.templates_dir - ) - file = tmpl_dir / f'{code}.html' + file = Path(common.templates_dir) / f'{code}.html' if not file.exists(): return diff --git a/app/main.py b/app/main.py index fed3553..642ebe0 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,7 @@ from typing import List, Type from fastapi import FastAPI from fastapi.staticfiles import StaticFiles -from .common import settings +from . import common # Add your paths here from .paths import Paths @@ -18,7 +18,7 @@ paths: List[Type[Paths]] = [ app = FastAPI() app.mount( '/static', - StaticFiles(directory=settings.static_dir), + StaticFiles(directory=common.static_dir), name='static', ) for p in paths: