The view function did not return a valid response. Flask-marshmallow, RestAPI

Viewed 721

I write application on Flask. For RestAPI I'm use flask-marshmallow. But I get error.

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 list. I do everything as in the example https://flask-marshmallow.readthedocs.io/en/latest/

class ApplicationSchema(ma.Schema):
    class Meta:
        fields = ("id", "name")

applications_schema = ApplicationSchema(many=True)

@bp.route("")
def applications():
    all_applications = Application.query.all()
    return applications_schema.dump(all_applications)
1 Answers

I was able to correct this by placing the return inside of jsonify. You can import it from flask and it'll look like this:

from flask import jsonify

@bp.route("")
    def applications():
        all_applications = Application.query.all()
        return jsonify(applications_schema.dump(all_applications))
Related