Django, how to see session data in the admin interface

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

    Continuing from Tomasz's answer, I went with:

    import pprint
    from django.contrib.sessions.models import Session
    class SessionAdmin(admin.ModelAdmin):
        def _session_data(self, obj):
            return pprint.pformat(obj.get_decoded()).replace('\n', '
    \n') _session_data.allow_tags=True list_display = ['session_key', '_session_data', 'expire_date'] readonly_fields = ['_session_data'] exclude = ['session_data'] date_hierarchy='expire_date' admin.site.register(Session, SessionAdmin)

提交回复
热议问题