python flask视图返回报错:TypeError: Object of type function is not JSON serializable

python flask视图返回报错:TypeError: Object of type function is not JSON serializable,第1张

原因 数组名不能有_

team_list = [
    {"id": 1, "name": "a"},
    {"id": 2, "name": "b"},
    {"id": 3, "name": "c"},
    {"id": 4, "name": "d"},
]
@app.route("/team/list")
def team_list():
    return jsonify(team_list)

报错

改成


teamlist = [
    {"id": 1, "name": "a"},
    {"id": 2, "name": "b"},
    {"id": 3, "name": "c"},
    {"id": 4, "name": "d"},
]
@app.route("/team/list")
def team_list():
    return jsonify(teamlist)

成功

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/922251.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存