Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop django from logging out after source changes

Tags:

django

session

I'm working on a django project and since a few days django keeps logging me of after I change a source file.

The expire date in the cookies and in the database show that theres still 1 month left.

Even after making the change the session cookie is the same as in the database but I have to login again. and after logging in both sessionids (database and browser) change.

I'm using django 1.8.5

edit: some session related settings:

SESSION_EXPIRE_AT_BROWSER_CLOSE        False
SESSION_COOKIE_HTTPONLY                True
SESSION_COOKIE_DOMAIN                  None
SESSION_SAVE_EVERY_REQUEST             False
SESSION_COOKIE_SECURE                  False

edit2:

Just to be a bit more clear: After changing some source file (python files, templates work just fine) the server will reload (if I use --noreload, I have to do it manually to get the changes), after that everyone is logged out.

edit3:

CACHES              {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
SESSION_ENGINE      'django.contrib.sessions.backends.db'
like image 262
Soraphis Avatar asked Oct 29 '15 11:10

Soraphis


1 Answers

Django has a SESSION_ENGINE setting that controls how the session information is stored on the server. One of the options is django.contrib.sessions.backends.cache, which stores session information only in cache memory.

Now, there's a certain cache backend - django.core.cache.backends.locmem.LocMemCache -, which stores information in the local python memory (for more info see CACHES). This cache backend is a typical choice for development, and of course resets each time the server is reloaded.

Using these two settings together would perfectly explain the situation you describe. Hope this helps!

like image 140
ppetrid Avatar answered Nov 03 '22 22:11

ppetrid