return bool as POST response using flask [duplicate]
You're not returning valid JSON. In JSON the boolean is lowercase, "true"
. You can use json.dumps
to generate the correct JSON serialization of a value. You should also set the content type of the response to application/json
. Use app.response_class
to build a response.
from flask import jsonreturn app.response_class(json.dumps(True), content_type='application/json')
Typically, you would send more than a single value as the response. Flask provides jsonify
as a shortcut to return a JSON object with the keys and values you pass it. (It's been improved in Flask dev version to handle other data besides objects.)
from flask import jsonifyreturn jsonify(result=True, id=id)