I am trying to track the user – without login. For that I tried using sessionid or django sessions.
View:
# Associating data with sessionid
ob = MyModel(session_key=request.session.session_key, data='abc')
ob.save()
Intention was to save specific data for each browser session.
Raises Error:
# session_key not found
I checked the cookies on the browser, there is only csrftoken.
sessionid was not in the cookie list.
I assumed that the sessionid is maintained no matter what ? But seems like that is not the case.
So, When is sessionid created ? How can I manage session without user login ?
The default behavior is to only populate the session if you access or modify a key in the
sessiondict-like object.To avoid this behavior set
SESSION_SAVE_EVERY_REQUESTtoTruein yoursettings.pyfile. This makes sure that a session is saved on each request, even if you didn’t modify the session object.The authentication middleware has no bearing on sessions; by default django supports anonymous sessions.