How to force a user logout in Django?

前端 未结 10 2143
粉色の甜心
粉色の甜心 2020-11-30 17:27

In my Django app under certain conditions I want to be able to force users to log out by a username. Not necessarily the current user who is logged in, but another user. So,

10条回答
  •  情深已故
    2020-11-30 18:24

    from django.contrib.sessions.models import Session

    deleting user session

    [s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_hash') == user.get_session_auth_hash()]
    

提交回复
热议问题