Delete session key from all users

前端 未结 3 1233
慢半拍i
慢半拍i 2020-12-10 15:23

When a user logs in some details are saved to the session, lets say using key=\'user_settings\'

When some updates happens within the system I need to loop through al

3条回答
  •  孤街浪徒
    2020-12-10 15:34

    You can access and update session data via the SessionStore object:

    from django.contrib.sessions.models import Session, SessionStore
    
    for session in Session.objects.all():
        store = SessionStore(session.session_key)
        del store['user_settings']
        store.save()
    

提交回复
热议问题