How to display all session variables ? i know that a variable can be accessed using request.session['variable']
but i wanted to know if there other variables that are set by others or set automatically during user logins or similar other events..
Django uses a cookie containing a special session id to identify each browser and its associated session with the site. The actual session data is stored in the site database by default (this is more secure than storing the data in a cookie, where they are more vulnerable to malicious users).
Django allows you to easily create session variables and manipulate them accordingly. The request object in Django has a session attribute, which creates, access and edits the session variables. This attribute acts like a dictionary, i.e., you can define the session names as keys and their value as values.
By default, Django saves session information in database (django_session table or collection), but you can configure the engine to store information using other ways like: in file or in cache. When session is enabled, every request (first argument of any view in Django) has a session (dict) attribute.
As referred by Daniel in comment.:
for key, value in request.session.items():
print('{} => {}'.format(key, value))
helpful answer: here and django docs
You can try like this
for key in request.session.keys():
print "key:=>" + request.session[key]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With