27

How can I display all session keys and valuesv? I know that the value can be accessed with request.session['key'] but I want to know if there are other values that are set by others or set automatically during user logins or similar other events..

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
sherpaurgen
  • 3,028
  • 6
  • 32
  • 45

2 Answers2

48

As referred by Daniel in comment.:

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

helpful answer: here and django docs

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
sherpaurgen
  • 3,028
  • 6
  • 32
  • 45
6

You can try like this

 for key in request.session.keys():
        print "key:=>" + request.session[key]
Robert
  • 3,373
  • 1
  • 18
  • 34
  • correct me if iam wrong but this is giving me value of the keys instead of keys. for example. key:=>johnson # name of user logged in key:=>a58f317f5ecc2eb686e576cda23372f1726c0b80 key:=>9 key:=>django.contrib.auth.backends.ModelBackend – sherpaurgen Sep 20 '17 at 17:05
  • 3
    Really you want `for key, value in request.session.items(): print('{} => {}'.format(key, value))`. – Daniel Roseman Sep 20 '17 at 18:12