load the data from the key itself instead of fetching from some external data store opposite of getsessionkey raise badsignature if signature fails this doesn t handle nondefault expiry dates see 19201 badsignature valueerror or unpickling exceptions if any of these happen reset the session to create a new key set the modified flag so that the cookie is set on the client for the current request to save get the session key as a securely signed string and then set the modified flag so that the cookie is set on the client for the current request this method makes sense when you re talking to a shared resource but it doesn t matter when you re storing the information in the client s cookie to delete clear the session key and the underlying data structure and set the modified flag so that the cookie is set on the client for the current request keep the same data but with a new key call save and it will automatically save a cookie with a new key at the end of the request instead of generating a random string generate a secure urlsafe base64encoded string of data as our session key load the data from the key itself instead of fetching from some external data store opposite of _get_session_key raise badsignature if signature fails this doesn t handle non default expiry dates see 19201 badsignature valueerror or unpickling exceptions if any of these happen reset the session to create a new key set the modified flag so that the cookie is set on the client for the current request to save get the session key as a securely signed string and then set the modified flag so that the cookie is set on the client for the current request this method makes sense when you re talking to a shared resource but it doesn t matter when you re storing the information in the client s cookie to delete clear the session key and the underlying data structure and set the modified flag so that the cookie is set on the client for the current request keep the same data but with a new key call save and it will automatically save a cookie with a new key at the end of the request instead of generating a random string generate a secure url safe base64 encoded string of data as our session key
from django.contrib.sessions.backends.base import SessionBase
from django.core import signing


class SessionStore(SessionBase):
    def load(self):
        
        try:
            return signing.loads(
                self.session_key,
                serializer=self.serializer,
                
                max_age=self.get_session_cookie_age(),
                salt="django.contrib.sessions.backends.signed_cookies",
            )
        except Exception:
            
            
            self.create()
        return {}

    def create(self):
        
        self.modified = True

    def save(self, must_create=False):
        
        self._session_key = self._get_session_key()
        self.modified = True

    def exists(self, session_key=None):
        
        return False

    def delete(self, session_key=None):
        
        self._session_key = ""
        self._session_cache = {}
        self.modified = True

    def cycle_key(self):
        
        self.save()

    def _get_session_key(self):
        
        return signing.dumps(
            self._session,
            compress=True,
            salt="django.contrib.sessions.backends.signed_cookies",
            serializer=self.serializer,
        )

    @classmethod
    def clear_expired(cls):
        pass