Active10 months ago
Flaskでソースの変更を検知して、Webアプリを自動リロードするPython Tips Flaskの開発で、ソースを更新したら、自動的にWebアプリをリロードする方法です。. Python post json 受信 (12). 単一のフォームデータ( request.form'fieldname' )を取得する代わりに、 request.formオブジェクトによって提供されるImmutableDictように解析することによって、すべての投稿データを取得できます。.
This question already has an answer here:
- How to get POSTed json in Flask? 4 answers
I am following this flask tutorial to learn about building an app in Python.
![Flask Flask](/uploads/1/2/5/8/125814925/200653063.jpg)
The tutorial (close to the end) talks about how to get a AJAX posted json inside python as follows:
HTML code:
Python Code:
When I run the script and click on the button 'Click me' in the browser, I get the '500 Internal Server Error' when I examine the Response in the browser. If I print the data variable, it prints out None in the terminal on the click event. I tried the suggestions given in the comments to use get_json(forced=true) in python script and stringify the 'cars' json in html file but in vain.
zingsyzingsy
![Con Con](/uploads/1/2/5/8/125814925/368584343.png)
marked as duplicate by davidism flaskDec 4 '17 at 14:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1 Answer
It looks like you didn't specify the content type of your post request look what is said in the official documentation:
By default this function will return None if the mimetype is not application/json but this can be overridden by the force parameter.
you need also to serialize you cars object to json object .
you can do something like this :
Renato Damas1,93522 gold badges1212 silver badges2626 bronze badges
Espoir MurhabaziEspoir Murhabazi2,20111 gold badge1515 silver badges3232 bronze badges