GAE Flask global variable persistent across browsers
<p>Here's my Flask setup:</p>

<p><code>main.py</code></p>

<pre><code>from flask import Flask
from app.views import main_bp

app = Flask(__name__)
app.register_blueprint(main_bp, url_prefix='')
</code></pre>

<p><code>app.config.py</code> (Shortened with "..." for this example)</p>

<pre><code>CONFIG = {
    'SITE_NAME': 'Test Site',
    'SSL': False,
    'DEBUG': True,
    'LOGGED_IN': False,
    ...
}
</code></pre>

<p><code>views.py</code></p>

<pre><code>from config import CONFIG

@main_bp.route('/')
@main_bp.route('/&lt;page_slug&gt;/')
def fallback(page_slug='home'):
    # Check if logged in
    if CONFIG['LOGGED_IN']:
        return 'Logged In'
    else
        return 'Logged Out'
</code></pre>

<p>Now if I change <code>CONFIG['LOGGED_IN']</code> to <code>True</code> in one of my browsers (Let's say Google Chrome), and then open another browser to the website (Let's say Firefox), then I'm already logged in on both. If I then log out in Firefox and refresh Chrome, I'm logged out on both.</p>

<p>When I was using Django I never noticed a problem like this... my global CONFIG variable is persisting across browsers. Weird!</p>

<p>Do I need to make my CONFIG into a class? Maybe this only happens when running through dev_appserver.py and won't happen in production? I'm still learning, so please be nice! Thanks :)</p>

<p>Note: Please ignore the blatant security issues with this example. I assure you this is not how I plan to use this code.</p>

<p>As davidism pointed out, I should not be storing variables that change per session as a global. I will instead decide on these variables after loading pertinent session variables like UID and Session ID.</p>

<p>Thanks.</p>

<p>Update: Athough, I find it interesting that Flask documentation would advocate setting globals via <code>g</code> (see: <a href="http://flask.pocoo.org/docs/0.11/api/" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/</a>)</p>

python google-app-engine flask