clearsessions.py 634 B

12345678910111213141516
  1. from importlib import import_module
  2. from django.conf import settings
  3. from django.core.management.base import NoArgsCommand
  4. class Command(NoArgsCommand):
  5. help = "Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)."
  6. def handle_noargs(self, **options):
  7. engine = import_module(settings.SESSION_ENGINE)
  8. try:
  9. engine.SessionStore.clear_expired()
  10. except NotImplementedError:
  11. self.stderr.write("Session engine '%s' doesn't support clearing "
  12. "expired sessions.\n" % settings.SESSION_ENGINE)