Skip to content

Instantly share code, notes, and snippets.

@melizeche
Created July 20, 2015 14:23
Show Gist options
  • Save melizeche/9155f599b171f6334248 to your computer and use it in GitHub Desktop.
Save melizeche/9155f599b171f6334248 to your computer and use it in GitHub Desktop.
How to ban/kick a logged in user in django
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
# grab the user in question
user = User.objects.get(username='johndoe')
[s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == user.id]
user.is_active = False
user.save()
@melizeche
Copy link
Author

you can run this from Django shell
./manage.py shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment