Django: session database table cleanup

心已入冬 提交于 2019-12-09 05:02:40

问题


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


回答1:


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



回答2:


  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




回答3:


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).



来源:https://stackoverflow.com/questions/7296159/django-session-database-table-cleanup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!