-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (33 loc) · 1.07 KB
/
main.py
File metadata and controls
41 lines (33 loc) · 1.07 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
posts: list[dict] = [
{
"id": 1,
"author": "Corey Schafer",
"title": "FastAPI is Awesome",
"content": "This framework is really easy to use and super fast.",
"date_posted": "April 20, 2025",
},
{
"id": 2,
"author": "Jane Doe",
"title": "Python is Great for Web Development",
"content": "Python is a great language for web development, and FastAPI makes it even better.",
"date_posted": "April 21, 2025",
},
]
@app.get("/", include_in_schema=False, name="home")
@app.get("/posts", include_in_schema=False, name="posts")
def home(request: Request):
return templates.TemplateResponse(
request,
"home.html",
{"posts": posts, "title": "Home"},
)
@app.get("/api/posts")
def get_posts():
return posts