Skip to content

Commit 4b3b471

Browse files
committed
Update code from review and fix requirements.txt file
1 parent e684693 commit 4b3b471

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

fastapi-jinja2-template/main.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,13 @@
1212
templates = Jinja2Templates(directory="templates")
1313

1414

15-
def generate_color():
16-
return f"#{''.join(random.choices(hexdigits.lower(), k=6))}"
17-
18-
1915
@app.get("/", response_class=HTMLResponse)
20-
def home():
21-
html = """
22-
<!DOCTYPE html>
23-
<html lang="en">
24-
<head>
25-
<meta charset="UTF-8">
26-
<title>Home</title>
27-
</head>
28-
<body>
29-
<h1>Welcome to FastAPI!</h1>
30-
</body>
31-
</html>
32-
"""
33-
return html
34-
35-
36-
@app.get("/random-color", response_class=HTMLResponse)
37-
def random_color(request: Request):
38-
color = generate_color()
16+
def home(request: Request):
17+
hex_chars = "".join(random.choices(hexdigits.lower(), k=6))
18+
hex_color = f"#{hex_chars}"
19+
context = {
20+
"color": hex_color,
21+
}
3922
return templates.TemplateResponse(
40-
request=request, name="color.html", context={"color": color}
23+
request=request, name="color.html", context=context
4124
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fastapi==0.118.0
1+
fastapi[standard]==0.118.0

0 commit comments

Comments
 (0)