/
developer_atatanoff
/
Guide
Обзор
Документация
Войти
/
developer_atatanoff
/
Guide
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app.py
32 строки
1 KB
Alexey N. Tatanoff
fix
07 янв 2026, 00:20
07 янв 2026, 00:20
9caf40b
Код
Авторство
О чём код?
from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates from pydantic import BaseModel from loguru import logger app = FastAPI(title="Guide", root_path="/md") # Настраиваем шаблоны Jinja2 templates = Jinja2Templates(directory="templates") @app.get("/", response_class=HTMLResponse) async def root_handler(request: Request): """Возвращает главную страницу.""" return templates.TemplateResponse("index.html", {"request": request}) @app.get("/{template_name}", response_class=HTMLResponse) async def content(request: Request, template_name: str): """ Отвечает за динамическую подгрузку шаблонов по указанному имени. """ try: return templates.TemplateResponse(f"{template_name}.html", {"request": request}) except Exception as e: logger.error(f"Ошибка при обработке шаблона {template_name}: {e}") return HTMLResponse(content="Page Not Found", status_code=404) @app.get("/healthup") def get_data(): return {"status": "ok", "data": [1, 2, 3, 4, 5]}