Here is the line in the source django.contrib.auth.__init__.login , which is registered by the user.
request.session[SESSION_KEY] = user.id
Logging out completely clears the session, so the presence of this key is an authenticated user.
from django.contrib.auth import SESSION_KEY from django.contrib.sessions.models import Session try: session = Session.objects.get(session_key=my_key) session.get_decoded()[SESSION_KEY] return (True, "Authenticated") except (Session.DoesNotExist, KeyError): return (False, "Not authenticated")
PS: itβs good if you are not using db sessions to extract the mechanism from the session.
source share