Wednesday, June 24, 2015

Django Manipulating the Session without a request



Django: Lookup a session without a request

    from django.conf import settings
    from importlib import import_module
    engine = import_module(settings.SESSION_ENGINE)
    session_store = engine.SessionStore("new_or_existing_sessionID")
    uid = session_store.get('_auth_user_id')

    try:
        del session_store['session_key']
    except IndexError:
        pass

    session_store.save()

No comments: