【发布时间】:2020-04-15 05:39:38
【问题描述】:
我最近很难做到这一点,所以我想我会回答我自己的问题来提供帮助。玩了dir(Session.objects),导入from django.contrib.sessions.models import Session后发现了。
【问题讨论】:
我最近很难做到这一点,所以我想我会回答我自己的问题来提供帮助。玩了dir(Session.objects),导入from django.contrib.sessions.models import Session后发现了。
【问题讨论】:
我使用了这个,返回一个包含所有会话数据的字典列表。
from django.contrib.sessions.models import Session
sessions = Session.objects.iterator() # also works with Session.objects.get_queryset()
for session in sessions: # iterate over sessions
data = session.get_decoded() # decode the session data
data["session_key"] = session.session_key # normally the data doesn't include the session key, so add it
print(data)
【讨论】: