Django, how to see session data in the admin interface

后端 未结 4 1469
甜味超标
甜味超标 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:29

    You can do something like this:

    from django.contrib.sessions.models import Session
    class SessionAdmin(ModelAdmin):
        def _session_data(self, obj):
            return obj.get_decoded()
        list_display = ['session_key', '_session_data', 'expire_date']
    admin.site.register(Session, SessionAdmin)
    

    It might be even that get_decoded can be used directly in list_display. And in case there's some catch that prevents this from working ok, you can decode the session data yourself, based on the linked Django source.

提交回复
热议问题