How to force a user logout in Django?

前端 未结 10 2140
粉色の甜心
粉色の甜心 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:03

    You can also use direct django function to do that, it will update and logs out all other sessions for the user, except the current one.

    from django.contrib.auth import update_session_auth_hash
    update_session_auth_hash(self.request, user)
    

    Docs for update_session_auth_hash here.

提交回复
热议问题