I have a flask app with the following view:
@menus.route(\'/\', methods=[\"PUT\", \"POST\"])
def new():
return jsonify(request.json)
Ho
Use request.get_json() and set force to True:
@menus.route('/', methods=["PUT", "POST"])
def new():
return jsonify(request.get_json(force=True))
From the documentation:
By default this function will only load the json data if the mimetype is
application/jsonbut this can be overridden by the force parameter.Parameters:
- force – if set to True the mimetype is ignored.
For older Flask versions, < 0.10, if you want to be forgiving and allow for JSON, always, you can do the decode yourself, explicitly:
from flask import json
@menus.route('/', methods=["PUT", "POST"])
def new():
return jsonify(json.loads(request.data))