Flask-Login - How To Get Session ID
Am doing a project with Flask, Gevent and web socket using flask development server environment. I used flask_login. Here how can get i get the Unique Session ID for each connecti
Solution 1:
There is no session id.
Sessions in Flask are simply wrappers over cookies. What you save on it it's digitally signed and sent as a cookie to the client. When you make a request, that cookie is sent to your server and then verified and transformed in a Python object.
AFAIK, Flask-Login saves on the session the user ID.
To get total active connections, you can:
- At login, generate an unique id and save it on the session (
flask.session['uid'] = uuid.uuid4()
, for example), then save it on your database. - At logout, delete that unique id from the session (
del flask.session['uid']
) and also from your database. - Retrieve the count of active sessions using your favourite method (ORM/Raw SQL)
Solution 2:
The session id is in: flask.session['_id']
Post a Comment for "Flask-Login - How To Get Session ID"