JSON を POST 経由で Flask View に送信したいと考えています。
ここに私のコードがあります
js:
$.post('/blog/add/ajax',
{ "title": "hallo", "article": "test" },
function(data) {
console.log(data.title);
console.log(data.article);
},
"json"
);
パイ:
@app.route('/blog/add/ajax', methods=['POST', 'GET'])
def add_blog_ajax():
if request.method == 'POST':
title = request.json['title']
article = request.json['article']
blog = Blog(title, article)
db.session.add(blog)
db.session.commit()
return jsonify(title=title, article=article)
エラー:
TypeError: 'NoneType' object has no attribute '__getitem__'
私は何をすべきかわからない、そしてここで何がうまくいかないのか。