test4.py 623 B

123456789101112131415161718192021
  1. from fastapi import FastAPI, Request
  2. from fastapi.responses import HTMLResponse
  3. from fastapi.staticfiles import StaticFiles
  4. from fastapi.templating import Jinja2Templates
  5. app = FastAPI()
  6. app.mount("/static", StaticFiles(directory="static"), name="static")
  7. templates = Jinja2Templates(directory="templates")
  8. @app.get("/items/{id}", response_class=HTMLResponse)
  9. async def read_item(request: Request, id: int):
  10. x = 0
  11. nums = x + 11
  12. title = "報表"
  13. keyword = "關鍵字1"
  14. return templates.TemplateResponse("item.html", {"request": request, "id": id, "num": nums, "titles": title, "keyword":keyword})