from flask_marshmallow import Marshmallow
ma = Marshmallow()
class UserSchema(SQLAlchemyAutoSchema):
class Meta:
model = User
users = [User(), User(), User(), ...]
data = UserSchema().dump(users, many=True)
res = make_response(data)
File "C:\Users\...\flask\app.py", line 2127, in make_response
raise TypeError(
TypeError: 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.
마시멜로우에서 dump를 했을 때 목록이면 결과가 list가 된다. 그리고 make_response는 사전형은 처리할 수 있는데 리스트는 처리하지 못해서 위와 같은 오류가 발생한다.
해결책은 그냥 jsonify를 사용해서 응답을 만들면 된다.
from flask import jsonify
...
res = jsonify(data)
끝.
'개발 > 파이썬' 카테고리의 다른 글
셀레니움을 위한 크롬 드라이버 자동 설치 (0) | 2021.12.25 |
---|---|
wxpython에서 항상 맨 위로 오는 윈도우 (0) | 2021.11.27 |
파일 확장자로 mimetype 추측하기 (0) | 2021.02.22 |
Google Drive에서 파일을 받으려는데 The requested conversion is not supported가 난다면 (0) | 2021.01.30 |
Compute engine (우분투 18.04 LTS)에 파이썬 설치 (0) | 2020.12.31 |
댓글