Coverage for docs_src/custom_response/tutorial004.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI 1abcde

2from fastapi.responses import HTMLResponse 1abcde

3 

4app = FastAPI() 1abcde

5 

6 

7def generate_html_response(): 1abcde

8 html_content = """ 1abcde

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) 1abcde

19 

20 

21@app.get("/items/", response_class=HTMLResponse) 1abcde

22async def read_items(): 1abcde

23 return generate_html_response() 1abcde