Reputation: 6777
Am trying to keep track of AnonymousUsers by their session information (if possible).
In older versions of Django, I could do something like:
def my_view(request):
# in case the user wasn't logged in, create/save a session
if not request.session.session_key:
request.session.save()
# would give me the key and on the next load it would persist
session_key = request.session.session_key
But with 1.6 (and I've been out of the game for a while) this results in a new unique session ID each time the request is put through. There is no persistence. I've tried to do a little reading but am going in circles as I'm out of Django practice.
How do I have a session persist? Do I need to write my own cookie handling?
Upvotes: 13
Views: 2936
Reputation: 6777
So, after I started reading through the source code I found myself on the global_settings.py file and found this gem:
SESSION_SAVE_EVERY_REQUEST = True
When I added that to the settings.py
file my problems were solved. AnonymousUsers got a session_key. Yipee!
Upvotes: 9