Django Session's Lifetime In Development Server
I am messing around with Session in my webapp at the moment and I noticed that whenever I restart the development server (the built-in server that came with Django), the session do
Solution 1:
change run server file
DJANGO_SETTINGS_MODULE="myproj.settings" \
python -c 'from django.contrib.sessions.models import Session; \
Session.objects.all().delete()'
python manage.py runserver
see here Django snippets: clear session table -> http://djangosnippets.org/snippets/48/
Solution 2:
Another solution is to use a non-persistent session backend. For example,
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
assumes: Django 1.0-1.5, using the default cache backend (LocMem)
Using the signed_cookies backend and clearing your browser's cookies could work too, but I haven't tried it.
Why?
Django uses the database as the session backend, by default
Default: django.contrib.sessions.backends.db
As a result, old sessions are restored from the database when the development server is reloaded. This holds true for the file and cached_db backends too.
Post a Comment for "Django Session's Lifetime In Development Server"