The value obtained by django request.session.session_key
is None
.
if not request.session.session_key:
request.session.create()
session_id = request.session.session_key
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.