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)
https://stackoverflow.com/questions/66619904/attribute-error-when-trying-to-use-jsonify-to-return-json March 14, 2021 at 08:28AM
没有评论:
发表评论