Django: session database table cleanup

2020-05-29 16:49发布

Does this table need to be purged or is it taken care automatically by Django?

3条回答
一夜七次
2楼-- · 2020-05-29 17:24

On my development server, I prefer a database command over python manage.py clearsessions because you delete all sessions, not just the expired ones (here: mysql). So login into your database and do:

truncate table django_session;

BTW, session is not a database, but a table (django_session) and an app (django.contrib.sessions).

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-05-29 17:36
  1. Django 1.6 or Above

    python manage.py clearsessions

  2. Django 1.5 or lower

    python manage.py cleanup

  3. From Django Shell

    from django.contrib.sessions.models import Session

    Session.objects.all().delete()

  4. django-session-cleanup cornJob

查看更多
我命由我不由天
4楼-- · 2020-05-29 17:39

Django does NOT provide automatic purging. There is however a handy command available to help you do it manually: https://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-store

python manage.py clearsessions
查看更多
登录 后发表回答