34👍
✅
According to John’s suggestion.
I fixed the problem by this snippet:
if not request.session.session_key:
request.session.save()
session_id = request.session.session_key
11👍
As per documentation:
SessionStore.create() is designed to create a new session (i.e. one
not loaded from the session store and with session_key=None). save()
is designed to save an existing session (i.e. one loaded from the
session store). Calling save() on a new session may also work but has
a small chance of generating a session_key that collides with an
existing one. create() calls save() and loops until an unused
session_key is generated.
Means it is safer to use create()
instead of save()
. So you can try like this:
if not request.session.session_key:
request.session.create()
session_id = request.session.session_key
- How to set timeout for urlfetch in Google App Engine?
- In django, is there a way to directly annotate a query with a related object in single query?
- How can I schedule a Task to execute at a specific time using celery?
- Django ALLOWED_HOSTS with ELB HealthCheck
- How can I disable a model field in a django form
Source:stackexchange.com