Last active
October 31, 2022 15:20
-
-
Save dbrgn/bae5329e17d2801a041e to your computer and use it in GitHub Desktop.
Manually create a Django session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import auth | |
from django.contrib.sessions.backends.db import SessionStore | |
session = SessionStore(None) | |
session.clear() | |
session.cycle_key() | |
session[auth.SESSION_KEY] = user._meta.pk.value_to_string(user) | |
session[auth.BACKEND_SESSION_KEY] = 'django.contrib.auth.backends.ModelBackend' | |
session[auth.HASH_SESSION_KEY] = user.get_session_auth_hash() | |
session.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked for me, GJ!