File tree Expand file tree Collapse file tree 2 files changed +8
-25
lines changed
Expand file tree Collapse file tree 2 files changed +8
-25
lines changed Original file line number Diff line number Diff line change 1212templates = 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 )
Original file line number Diff line number Diff line change 1- fastapi == 0.118.0
1+ fastapi [ standard ] == 0.118.0
You can’t perform that action at this time.
0 commit comments