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
|
from pydantic import BaseSettings
|
||||||
|
|
||||||
|
|
||||||
file_dir = Path(__file__).parent
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
secret_key: str = secrets.token_hex(32)
|
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()
|
settings = Settings()
|
||||||
|
|
||||||
|
|
||||||
templates = Jinja2Templates(
|
file_dir = Path(__file__).parent
|
||||||
directory=settings.templates_dir,
|
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 paths
|
||||||
from . import respond
|
from . import respond
|
||||||
from .common import settings
|
from . import common
|
||||||
|
|
||||||
# Add other HTTP error codes
|
# Add other HTTP error codes
|
||||||
codes = [404, 500]
|
codes = [404, 500]
|
||||||
|
@ -30,11 +30,7 @@ class ErrorsPaths(paths.Paths):
|
||||||
code (int): HTTP error code
|
code (int): HTTP error code
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tmpl_dir = (
|
file = Path(common.templates_dir) / f'{code}.html'
|
||||||
Path(__file__).parent /
|
|
||||||
settings.templates_dir
|
|
||||||
)
|
|
||||||
file = tmpl_dir / f'{code}.html'
|
|
||||||
|
|
||||||
if not file.exists():
|
if not file.exists():
|
||||||
return
|
return
|
||||||
|
|
|
@ -2,7 +2,7 @@ from typing import List, Type
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from .common import settings
|
from . import common
|
||||||
|
|
||||||
# Add your paths here
|
# Add your paths here
|
||||||
from .paths import Paths
|
from .paths import Paths
|
||||||
|
@ -18,7 +18,7 @@ paths: List[Type[Paths]] = [
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.mount(
|
app.mount(
|
||||||
'/static',
|
'/static',
|
||||||
StaticFiles(directory=settings.static_dir),
|
StaticFiles(directory=common.static_dir),
|
||||||
name='static',
|
name='static',
|
||||||
)
|
)
|
||||||
for p in paths:
|
for p in paths:
|
||||||
|
|
Loading…
Add table
Reference in a new issue