The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a (type(rv).__name__).
Package:
flask
56479

Exception Class:
TypeError
Raise code
raise TypeError(
f"{e}\nThe view function did not return a valid"
" response. The return type must be a string,"
" dict, tuple, Response instance, or WSGI"
f" callable, but it was a {type(rv).__name__}."
).with_traceback(sys.exc_info()[2])
else:
raise TypeError(
"The view function did not return a valid"
" response. The return type must be a string,"
" dict, tuple, Response instance, or WSGI"
f" callable, but it was a {type(rv).__name__}."
)
rv = t.cast(Response, rv)
# prefer
Links to the raise (1)
https://github.com/pallets/flask/blob/83f7efa04708a22c9701488f0f29b59c2b756bef/src/flask/app.py#L1714Ways to fix
The exception is thrown when the view function returning a non-valid response.
Reproduce an error
Let's create a simple flask application.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 531
In the above code, we returning an integer value in the view function but it is not allowed. An acceptable type can be a string, dict, tuple, Response instance, or WSGI callable.
Fix Version
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World!"
Add a possible fix
Please authorize to post fix