Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all session variables in django?

Tags:

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..

like image 480
sherpaurgen Avatar asked Sep 20 '17 16:09

sherpaurgen


People also ask

Where are Django session variables?

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).

What is session variable in Django?

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.

How is the session handling in Django?

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.


2 Answers

As referred by Daniel in comment.:

for key, value in request.session.items():
    print('{} => {}'.format(key, value))

helpful answer: here and django docs

like image 51
sherpaurgen Avatar answered Oct 02 '22 18:10

sherpaurgen


You can try like this

 for key in request.session.keys():
        print "key:=>" + request.session[key]
like image 31
Robert Avatar answered Oct 02 '22 19:10

Robert