When SessionMiddleware
is activated, each HttpRequest
object-the first argument to any Django view function-will have a session
attribute, which is a dictionary-like object. You can read it and write to request.session
at any point in your view. You can edit it multiple times.
All session objects inherit from the base class backends.base.SessionBase
. It has the following standard dictionary methods:
__getitem__(key)
__setitem__(key, value)
__delitem__(key)
__contains__(key)
get(key, default=None)
pop(key)
keys()
items()
setdefault()
clear()
It also has these methods:
Delete the current session data from the session and delete the session cookie. This is used if you want to ensure that the previous session data can't be accessed again from the user's browser (for example, the django.contrib.auth.logout()
function calls it).