title: KeyError when retrieving value from Flask session
body: <p>I have a Flask application that stores some values in a Database. These come from an HTML form. Some of these are added to Flask's session, using the following code:</p>
  
  <p><code>session['userID']=str(cur_var.getvalue())</code></p>
  
  <p>I have a debug HTML page that only shows whatever is stored in the current session. The code to render this page is as follows:</p>
  
  <pre><code>@app.route('/debug/')
  def debug():
      return str(session)
  </code></pre>
  
  <p>Once I open this page, </p>
  
  <pre><code>&lt;securecookiesession {'usercoord': 7.0,'userid': '53.0'}&gt;&lt;/securecookiesession&gt;
  </code></pre>
  
  <p>For what I understand, my session definitely has a <code>userid</code> key. </p>
  
  <p>However, when my Flask application is on another (unrendered) URL that tries to retrieve the userID from the current session:
  <code>new_address.append(float(session['userid']))</code></p>
  
  <p>I get the following error:</p>
  
  <pre><code>&lt;title&gt;KeyError: 'userid' // Werkzeug Debugger&lt;/title&gt;
  </code></pre>
  
  <p>Furthermore, I made a very simple webpage that should only print <code>session['userID']</code>. I use the following code in my Flask application:</p>
  
  <pre><code>@app.route('/print/')
  def printing():
      return render_template('print.html', printing=session['userid'])
  </code></pre>
  
  <p>And this is the print.html template:</p>
  
  <pre><code>{% extends "layout.html" %}
  {% block content %}
  {{ printing }}
  {% endblock %}
  </code></pre>
  
  <p>This yields the following error:</p>
  
  <pre><code>builtins.KeyError
  KeyError: 'userid'
  </code></pre>
  
  <p>I already tried this same logic on a much smaller application, and it worked fine. Where could my error be here?</p>
  
  <p>Thank you very much for any help you can provide.</p>
  
  <p>P.S.
  If it is of any use, I am handling the interaction between the webpages and my Flask application with jQuery and using AJAX to post the data.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After remaking the project to reduce it to a much simpler one, I have found that sometimes (for a reason I do not understand), adding a new value to the Flask session will not work. For example, if I include this line of code:</p>
  
  <p><code>session['coordid']=float(cur_var.getvalue())</code></p>
  
  <p>And check in my print.html page the value of <code>str(session)</code>, I do not see the key <code>coordid</code>.</p>