Debian Codegraph @

docs_src/custom_response/tutorial004_py310.py

raw
1 from fastapi import FastAPI
2 from fastapi.responses import HTMLResponse
3
4 app = FastAPI()
5
6
7 def generate_html_response():
8 html_content = """
9 <html>
10 <head>
11 <title>Some HTML in here</title>
12 </head>
13 <body>
14 <h1>Look ma! HTML!</h1>
15 </body>
16 </html>
17 """
18 return HTMLResponse(content=html_content, status_code=200)
19
20
21 @app.get("/items/", response_class=HTMLResponse)
22 async def read_items():
23 return generate_html_response()