FastAPIApp/
├── app.py
├── templates/
│ └── index.html
├── static/
│ └── flask-logo.png
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("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to FastAPI</title>
</head>
<body>
<h1>Welcome to FastAPI</h1>
<img src="{{ url_for('static', path='/flask-logo.png') }}" alt="Flask Logo" />
<p>Welcome to FastAPI's documentation. Get started with <a href="#">installation</a>
and then get an overview with the <a href="#">quickstart</a>. There is also a
more detailed <a href="#">tutorial</a> that shows how to create a small but
complete application with FastAPI. Common patterns are described in the
<a href="#">patterns</a> section. The rest of the docs describe each
component of FastAPI in detail, with a full reference in the <a href="#">API</a>
section.</p>
</body>
</html>
Reverts commit 4d69165ab6. Now that a
release has this option, it's ok to show it in the docs. It had been
reverted because the 2.2.x docs showed it before 2.2.3 was released.
Remove the `--eager-loading/--lazy-loading` options and the
`DispatchingApp` middleware. The `run` command handles loading
exceptions directly. The reloader always prints out tracebacks
immediately and always defers raising the error.