title: Flask session not persisting
body: <p>I have a web application running on a Flask backend with a JS client handling the front-end work. I'm running into problems trying to save a key-value pair to Flask's session object (<code>flask.session</code>) through a simple Flask API.</p>
  
  <p>The session object I'm trying to modify is called <code>account_id</code> and the two API routes basically look like this:</p>
  
  <p><strong>GET</strong></p>
  
  <pre><code>@access_service.route('/current_account.json', methods=['GET'])
  @login_required
  def show_current_account():
      return jsonify(account_id=session.get('account_id'))
  </code></pre>
  
  <p><strong>POST</strong></p>
  
  <pre><code>@access_service.route('/current_account.json', methods=['POST'])
  @login_required
  def update_current_account():
  if request.json:
      session['account_id'] = request.json['account_id']
      return jsonify(account_id=session.get('account_id'))
  return jsonify()
  </code></pre>
  
  <p>In the JS frontend a call to the POST route is made as follows:</p>
  
  <pre><code>$.ajax({
    url: '/current_account.json',
    contentType: 'application/json',
    type: 'POST',
    data: JSON.stringify({ 'account_id': 10 })
  });
  </code></pre>
  
  <p>Which does appear to work correctly, the ajax call returns with 200 OK and a correct return value. Logging from the Flask application also reveals that the session now contains the key <code>account_id</code> with value 10. However, looking up <code>/current_account.json</code> immediately after the POST request is made simply returns an <code>account_id</code> with value <code>null</code>.</p>
  
  <p>What's stranger still is that using a simple in-browser REST client and making an identical POST request to <code>current_account.json</code> causes the session to work and persist as expected through full-page refresh, etc. Since that is the case, it leads me to believe that the problem has to do with the request itself rather than with Flask's session object, although I can't seem to figure out what exactly is causing it.</p>