Zalthorius kun
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>
This commit is contained in:
parent
db7d2d2d68
commit
0606ae717f
1 changed files with 0 additions and 0 deletions
Loading…
Add table
Add a link
Reference in a new issue