Skip to content Skip to sidebar Skip to footer

Flask Blueprint Putting Something On Session

I was trying to put session['logged_in'] = True in the session, but in another blueprint it doesn't persist... Why is that? Is there any better way to keep something in the sessi

Solution 1:

I think I understand your confusion now~

Your flask session won't store anything on the server. the 'session' dict is filled by the cookies from the client request.

Again. that is:

client make login request to server, and got a [login success] response as well as a [cookies] which contains the !!!sessionINFO!!! you think are stored on the server side.

Next time, you must send the whole cookies to the server again, then your session in the server may have data.

Browser will do this for you. If you use a local client, say python requests library. Then be sure you are making requests with session (for requests-lib, it's requests.Session())

------------------OLD-------------------------------------

Though not an expert, but the case you described should not have happened.

The session is cookies data encrypted with a secret, if you have gone through the document mentioned by Beqa.

Just set

app.secret = '........'

And use session as a dict.

just FYI,

client request---->server (encrypt your_data 'logged_in' and client_relating_data 'maybe: ip, host or etc.', and put the encrypted info in cookies 'session=....') ------> client (get response with cookies)

client request again -----> server (decrypt the cookie 'session=...' with your secret), find the 'logged_in' data and know you are logged in.)

the cookies is something like below.

So, I'm not sure what's actually your trouble when using session, and put some basic information here. Just hope it helps in case.

enter image description here

Post a Comment for "Flask Blueprint Putting Something On Session"