[Fixed]-Django 1.5 Session Key is None

31👍

To answer my own question:

It is still possible to access the session key using {{ request.session.session_key }}. However, the docs mention that a session will only be created if you’ve saved/modified the session.

By default, Django only saves to the session database when the session
has been modified – that is if any of its dictionary values have been
assigned or deleted:

So in my case, the session wasn’t being set because I wasn’t manipulating it. Using SESSION_SAVE_EVERY_REQUEST will indeed solve the problem globally. In my use case, I only needed it on a particular view function so it was a simple matter of doing this:

if not request.session.get('has_session'):
    request.session['has_session'] = True
👤super9

Leave a comment