templates/static paths bugfixes
This commit is contained in:
parent
107dbfaf7b
commit
61be530920
3 changed files with 15 additions and 18 deletions
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue