votes up 1

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
github stars 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
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up -2 votes down

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!"
Sep 29, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix