5

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)
  • There is a similar complaint here: https://github.com/jmcarp/flask-apispec/issues/160 ... I think it's an incompatibility in the latest version(s) of Flask. Perhaps Flask used to accept a list as output, but it no longer does? – Ethan T Jan 16 '20 at 16:59
  • change `dump` to `dumps` :) – Ranvijay Sachan Jul 20 '22 at 11:19

1 Answers1

2

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))