简体   繁体   中英

Client-side variables in Flask?

Right now, I'm porting an app I wrote from PHP to Flask, and I've already hit a roadblock on day 2; the original app relied heavily on client-side variables, stored in the $_SESSION array. I can't seem to find a way to do the same in Flask, which is really quite frustrating.

I've tried using JavaScript to do the same tasks, but it ends up being much slower and less reliable than PHP's client-side variable storing method.

Where should I start with this in Flask? Any particular extensions I should look in to? What's the best practice Is it even possible?

Thanks in advance!

Flask provides a session object . This object is stored on the client side as a signed cookie (I imagine $_SESSION is similar). It requires that Flask.secret_key be set. The object can be modified like a dict.

from flask import session

color = 'blue'
session['usr_fav_color'] = color

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM