mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-24 22:59:32 -05:00
* 📝 Update docs for compatibility with Starlette 0.29.0 and new template arguments * ⬆️ Upgrade Starlette to >=0.29.0,<0.33.0 * 📌 Remove AnyIO pin
19 lines
521 B
Python
19 lines
521 B
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
app = FastAPI()
|
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
|
|
@app.get("/items/{id}", response_class=HTMLResponse)
|
|
async def read_item(request: Request, id: str):
|
|
return templates.TemplateResponse(
|
|
request=request, name="item.html", context={"id": id}
|
|
)
|