Flask JSON post request not working
<p>I am using react to submit a form to a flask backend. The data is submitted in json this is an example.</p>

<pre><code>add_new_user(e){
  e.preventDefault()
  var user_details = {}
  user_details['fname'] = this.state.first_name
  user_details['last_name'] = this.state.last_name

var post_request = new Request('http://127.0.0.1:5000/add_new_user', {
    method: 'post',
    body: JSON.stringify(user_details)
})

fetch(post_request).then(function(response){
    console.log(response)
})
</code></pre>

<p>On my backend the code looks like this,</p>

<pre><code>@app.route('/add_new_user', methods=['POST'])
def add_user():
    content = request.json()
    print content
    return 'user added'
</code></pre>

<p>However the content variable is null and therefore the printed data on the screen is None. How can I fix this? What am I doing wrong. Thanks</p>

<p>Try <code>request.get_json(force=True)</code>. It's recommended to use <code>get_json()</code> instead of the <code>json()</code> method. <code>force=True</code> allows to ignore content type requirement. </p>

javascript python json node.js reactjs