sander
если mimetype кривой то
request.get_json(force=True)
То же самое: None.
Чтобы не гадать на кофейной гуще, вот тестовый пример:
app.py#!/usr/bin/env python
from flask import Flask, request, jsonify
app = Flask(__name__)
app.debug = True
template = """
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function()
{
data = [{'email': 'john@example.com', 'name': 'John Smith'},
{'email': 'thomas@example.com', 'name': 'Thomas Sendall'}];
$('button').on('click', send_request);
function send_request() {
$.ajax({
url: '/',
type: 'POST',
data: data,
success: function (data) {
$("span").html(data.message)
}
});
};
});
</script>
</head>
<body>
<div style="position: absolute; margin-left: 45%;">
<button style="background-color:red; width: 15rem; height:12rem;">Big Red Button</button>
<h1>Result: <span></span></h1>
</div>
</body>
</html>
"""
@app.route('/', methods=['GET'])
def hello():
return template
@app.route('/', methods=['POST'])
def processing():
return jsonify({'status': 'ok',
'message': str(request.form.keys())})
if __name__ == "__main__":
app.run()