Skip to content

Instantly share code, notes, and snippets.

@eugena
Created September 16, 2015 14:28
Show Gist options
  • Save eugena/6ea6e82e11d21869ad7d to your computer and use it in GitHub Desktop.
Save eugena/6ea6e82e11d21869ad7d to your computer and use it in GitHub Desktop.
import importlib
from django.conf import settings
from django.contrib.auth import SESSION_KEY
def get_id_by_session_key(session_key):
"""
Returns user identifier by session_key
"""
session_store_module = importlib.import_module(settings.SESSION_ENGINE)
store = session_store_module.SessionStore(session_key=session_key)
return User._meta.pk.to_python(store[SESSION_KEY])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment