Django, how to see session data in the admin interface

后端 未结 4 1473
甜味超标
甜味超标 2021-02-18 19:09

I\'m using Django sessions and I would like a way of seeing the session data in the admin interface. Is this possible?

I.e. for each session I want to see the data store

4条回答
  •  长情又很酷
    2021-02-18 19:51

    Session data is contained in a base64 encoded pickled dictionary. That's is what you're seeing in the admin because that data is stored in a TextField in the Session model.

    I don't think any distributed django code stores the ip address in the session but you could do it yourself if you can access it.

    In order to display the real session information, you may write your own form field that presents the decoded information. Keep in mind that you'll have to also overwrite the save method if you want to modify it. You can take a look at the encode and decode methods in django/contrib/sessions/models.py.

提交回复
热议问题