[Flask] Sessions and blueprints and Application context

Ben Duncan linux4ms at gmail.com
Sat Nov 30 13:40:17 EST 2019


Awesome, thanks!
*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Sat, Nov 30, 2019 at 8:54 AM Badri Sunderarajan <badrihippo at gmail.com>
wrote:

> Yes, session can only be accessed within a request context, which would
> in practical terms mean it needs to be called from within a view. Each
> client (read: browser) which loads the page gets its own session, so it
> doesn't make sense to define a "global" session for everyone.
>
> Depending on what you're trying to do, you could set the session variable
> within a view like
>
> @app.route('/')
> def home():
>     session['myvar'] = 'MYVAR' # sets variable for this particular session
>     return 'Hello, session!'
>
> On the other hand, if you want the variable to be global for the whole
> app, you should probably be setting app.config or something instead of
> using session variables.
>
> Hope that helps!
>
> Badri
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20191130/0a7b9dd2/attachment.html>


More information about the Flask mailing list