The value obtained by django request.session.session_key is None

created at 07-17-2021 views: 2

description

The value obtained by django request.session.session_key is None.

solution

if not request.session.session_key:
    request.session.create()
session_id = request.session.session_key

reason of using create() to post save()

SessionStore.create() is used to create a new session (session_key=None that is not loaded from the session store).

save() is used to save the existing session (that is, the session loaded from the session store).

Calling save() for a new session may also be effective, but the possibility of session_key conflicting with an existing session is very small. create() calls save() and loops until the session_key is generated unused.

Please log in to leave a comment.