尝试使用 jsonify 返回 json 时出现属性错误

问题描述

我对 python 比较陌生,我正在尝试在烧瓶中使用 jsonify。我查看了一些基本的在线示例并尝试复制:-

@app.route('/json')
def getjson():
  info = {
      'yes':'success','at last':'it works'
  }
  return jsonify(info)

当我尝试访问 /json 时出现错误:-

AttributeError: 'Request' 对象没有属性 'is_xhr'

这超出了我的范围,我不确定从哪里开始调试。任何帮助将不胜感激。

完整代码

# Import the Flask class form the flask module
from flask import Flask,jsonify


# create the application object based on Flask class
appjson= Flask(__name__)

@appjson.route('/json')
def getjson():
    info = {
        'yes':'success','at last':'it works'
        }
    return jsonify(info)



# start the server with the run() method
if __name__ =='__main__':
    appjson.run(debug=True)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)