python [Django]清除特定用户的所有会话

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [Django]清除特定用户的所有会话相关的知识,希望对你有一定的参考价值。

import datetime
from django.contrib.sessions.models import Session

def clear_sessions_of_user(user_pk):
    for session in Session.objects.filter():
        session_data = session.get_decoded()
        if str(session_data.get('_auth_user_id')) == str(user_pk):
            session.delete()
            print(session_data)


# clear_sessions_of_user(8)

以上是关于python [Django]清除特定用户的所有会话的主要内容,如果未能解决你的问题,请参考以下文章