简体   繁体   English

在 Django 中删除特定用户的会话?

[英]delete session of a specific user in django?

I am trying to delete the session of some specific user in Django.The code seems to run perfectly fine but I believe session is not deleted as the user is still logged in. The code I am using to delete session is:-我正在尝试删除 Django 中某个特定用户的会话。代码似乎运行得很好,但我相信会话不会被删除,因为用户仍然登录。我用来删除会话的代码是:-

user = User.objects.get(id=id)
for s in Session.objects.all():
            if s.get_decoded().get('_auth_user_id') == user.id:
                s.delete()

//类型转换为相同的类型,否则它们将始终返回 False

user = User.objects.get(id=id) for s in Session.objects.all(): if int(s.get_decoded().get('_auth_user_id')) == int(user.id): s.delete()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM