title: KeyError when using session in Flask
body: <p>So I am trying to pass a value from one html page to another using flask. The code I have written looks like this:</p>
  
  <pre><code>from flask import Flask, render_template
  from flask import request, session, url_for,abort,redirect
  
  app = Flask(__name__)
  
  app.config['SECRET_KEY'] = 'oh_so_secret'
  
  
  @app.route('/'):
  def first():
      session['this_one']='hello'
      render('template.html')
  
  @app.route('/second')
  def second():
     it=session['this_one']
      render('other_page.html')
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>but when I run this I get a <code>KeyError:this_one</code>.</p>
  
  <p>So, it works today, having restarted the system. I then made some changes:</p>
  
  <pre><code>@app.route('/'):
  def first():
      session['this_one']='goodbye'
      render('template.html')
  
  @app.route('/second')
  def second():
     it=session['this_one']
     render('other_page.html')
  </code></pre>
  
  <p>and the second function is still returning <code>hello</code>.</p>
  
  <p>So it seems that the <code>session</code> dictionary is not being overwritten as I would want it to be.</p>
  
  <h2>Follow Up</h2>
  
  <p>This is a real mystery, it works one day then not the next with no changes being made. Now in the rout <code>('/')</code> I am setting a list:</p>
  
  <pre><code>@app.route('/'):
  def first():
      session['this_one']='hello'
      session['a_list']=['a','b','c']
      render('template.html')
  </code></pre>
  
  <p>calling it in the second function with a print command:</p>
  
  <pre><code>@app.route('/second')
  def second():
      it=session['this_one']
      print(session['a_list'])
      render('other_page.html')
  </code></pre>
  
  <p>and an empty list <code>[]</code> is returned.</p>