Clearing sessions in django_session table without logging out current users

前端 未结 3 1275
醉酒成梦
醉酒成梦 2021-02-08 07:17

I am working on sessions in Django.

By default, django stores sessions in django_session, I found out there is no way to purge sessions.

Though

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 08:01

    1. Django 1.6 or Above

      python manage.py clearsessions

    2. Django 1.5 or lower

      python manage.py cleanup

    3. From Django Shell

      from django.contrib.sessions.models import Session
      Session.objects.all().delete()
      
    4. django-session-cleanup cronJob

    5. clearing session in logout( based on session key present in request)

    from django.contrib.sessions.models import Session  
    session_key = request.data['sessionKey']
    session = Session.objects.get(session_key=session_key)
    Session.objects.filter(session_key=session).delete()
    Session.objects.all().delete()
    

提交回复
热议问题