ModuleNotFoundError: No module named 'fastapi.responses'

Viewed 2951

I am trying to use HTMLResponse from FastAPI, as described in the documentation. I'm on version 0.70. I keep getting the following error:

ModuleNotFoundError: No module named 'fastapi.responses'

My code is shown below:

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)

Any ideas?

1 Answers

Since FastAPI is built on top of Starlette, try this:

from starlette.responses import HTMLResponse
Related