开发者

Finding inactive session files in Django

开发者 https://www.devze.com 2023-01-27 20:01 出处:网络
I use django sessions with fi开发者_Python百科le system backend. I have set SESSION_EXPIRE_AT_BROWSER_CLOSE to True. So my current session becomes invalid when the browser closes. But the session file

I use django sessions with fi开发者_Python百科le system backend. I have set SESSION_EXPIRE_AT_BROWSER_CLOSE to True. So my current session becomes invalid when the browser closes. But the session file created remains.

I want to delete all inactive/invalid files. How can I find these files?


Note that this setting means that the cookie (on the client side!) is deleted after the browser is closed. The session on the server remains until it has expired.

Sessions are stored in the database backend of the Django site. If you want to clear all open sessions, check out Clearing the session table.


You may consider to use

python manage.py cleanup

for deleting this files.


The way to handle this, as of Django 1.5 and later, is to use the new "clearsessions" command available from django-admin.py and manage.py. It clears out file-based sessions, which the "cleanup" command didn't do. As an example usage, you could set up a cron job to regularly run:

django-admin.py clearsessions

(make sure the cron job can access the DJANGO_SETTINGS_MODULE environment variable)

For more information, see the docs.

0

精彩评论

暂无评论...
验证码 换一张
取 消