Attribute error when trying to use jsonify to return json

29 Views Asked by At

I'm relatively new to python and I'm trying to get to grips with jsonify within flask. I've looked at some basic online examples and tried to replicate:-

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

When I try to access /json I get an error:-

AttributeError: 'Request' object has no attribute 'is_xhr'

This is beyond me and I'm not sure where to start in debugging. ANy help would be appreciated.

full code

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

There are 0 best solutions below