-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfastapi.py
More file actions
27 lines (19 loc) · 870 Bytes
/
fastapi.py
File metadata and controls
27 lines (19 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastapi import FastAPI, Response
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from asgi_htmx import HtmxMiddleware
from asgi_htmx import HtmxRequest as Request
from .common import HERE, make_table
app = FastAPI()
app.mount("/static", StaticFiles(directory=HERE / "static"), name="static")
app.add_middleware(HtmxMiddleware)
templates = Jinja2Templates(directory=HERE / "templates")
@app.get("/", name="home")
async def home(request: Request) -> Response:
return templates.TemplateResponse("home.html", {"request": request})
@app.get("/result", name="result")
async def result(request: Request) -> Response:
assert (htmx := request.scope["htmx"])
template = "partials/result.html"
context = {"request": request, "table": make_table(htmx)}
return templates.TemplateResponse(template, context)