SKS*_*S81 5 python api fastapi
我正在尝试使用HTMLResponseFastAPI,如文档中所述。我的版本是0.70。我不断收到以下错误:
ModuleNotFoundError: No module named 'fastapi.responses'
Run Code Online (Sandbox Code Playgroud)
我的代码如下所示:
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import os
from os import curdir, environ as env
app = FastAPI()
name='fred'
@app.get("/getName")
def returnName():
html_content = """
<html>
<head>
<title>Some HTML in here</title>
</head>
<body>
<h1>Name is {{name}}</h1>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
小智 1
由于 FastAPI 是构建在 Starlette 之上的,请尝试以下操作:
from starlette.responses import HTMLResponse
Run Code Online (Sandbox Code Playgroud)