title: Passing a flask session variable to a different view returns type None
body: <p>I am trying to pass a session variable that is set on the login view, to another view. However, the session variable always returns None if a form is submitted, I want the session variable to retain. </p>
  
  <p>The tools page has some form fields, and one text box that handles autocomplete search based off of the session['foo'] which is sent on good login.</p>
  
  <pre><code>@app.route('/login', methods=['GET', 'POST'])
  def login():
      if request.method == 'POST':
          # Get some form variables here
          if login is valid:
              login_user(user, remember=True)
              session['foo'] = utils.get_data()
              return redirect(url_for('tools'))
      return render_template('login.html')
  
  @app.route("/tools", methods=['GET', 'POST'])
  @login_required
  def tools():
      if session['foo'] is None:
          print "Data is None type, getting data"
          session['foo'] = utils.get_data()
  
      if request.method == 'POST':
          # Handling some forms here
          # If one of these forms are submitted, session['foo'] is set to None :(
  
      return render_template('tools.html', foo_data=session['foo'])
  </code></pre>
  
  <p>Utils.py</p>
  
  <pre><code>def get_data():
      response = requests.post(url, data=data)  # FYI, server won't allow GET for this call.
      # Do json type stuff here to make response.content nice for javascript
     return response
  </code></pre>
  
  <p>Essentially, what happens with this code is, every time I submit a form, I have to check if it's None and invoke utils.get_data(), I want the data returned by this method to retain for the entire length of the session. </p>
  
  <p>EDIT:
  Solution, session variable object is too big. Some ways to solve this could include;</p>
  
  <ul>
  <li>Use AJAX to avoid refresh the page each submission, thus not flushing the session object</li>
  <li>Split the object into smaller chunks</li>
  <li>Avoid storing large objects in cookies- use local storage</li>
  </ul>