To get request.form
as a normal dictionary , use request.form.to_dict(flat=False)
.
To return JSON data for an API, pass it to jsonify
.
This example returns form data as JSON data.
@app.route('/form_to_json', methods=['POST'])
def form_to_json():
data = request.form.to_dict(flat=False)
return jsonify(data)
Here's an example of POST form data with curl, returning as JSON:
$ curl http://127.0.0.1:5000/data -d "name=ivanleoncz&role=Software Developer"
{
"name": "ivanleoncz",
"role": "Software Developer"
}