lavkach3
1from datetime import datetime
2from uuid import uuid4
3
4from jinja2 import Environment, FileSystemLoader, select_autoescape
5from starlette.exceptions import HTTPException
6from starlette.requests import Request
7from starlette.templating import Jinja2Templates
8
9from app.front.front_config import config
10
11
12
13template_path = "app/front/templates/"
14
15templates = Jinja2Templates(directory=template_path)
16environment = templates.env
17templates.env.globals['datetime'] = datetime
18templates.env.globals['uuid'] = uuid4
19templates.env.globals['now'] = datetime.date(datetime.now()).isoformat()
20templates.env.globals['ws'] = f"ws://{config.MESSAGE_HOST}:{config.MESSAGE_PORT}/api/bus/ws/bus"
21
22
23async def internal_error(request: Request, exc: HTTPException):
24return templates.TemplateResponse('base/toast.html', {'request': request}, status_code=500)
25
26
27exception_handlers = {
28500: internal_error
29}
30