title: How can I detect whether a variable exists in Flask session?
body: <p>I would like to detect if a session['logged_in'] key exists, which means my user has already logged in.</p>
  
  <p>For Example:</p>
  
  <pre><code>if (session['logged_in'] != None):
      if session['logged_in'] == True:
          return redirect(url_for('hello'))
  </code></pre>
  
  <p>However, if the key 'logged_in' doesnt exist it therefore generates an error. As a session object is like a dictionary I thought I would be able to use the had_key() method, but this doesn't seem to work either. Is there an easy way to detect if a session contains data without generating an error?</p>