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'
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!
Related
When I close a tab or browser and then I run the application again opening the browser again, the previous session remains active. I tried SESSION_EXPIRE_AT_BROWSER_CLOSE = True in settings.py file in the project directory as per the Django documentation. Nothing works. Even the existing solutions in stackoverflow does not work. Is there any way to clear the session on a browser or tab close in Django?
I looked through some web sources, and the reason could be that your session already existed before you set up SESSION_EXPIRE_AT_BROWSER_CLOSE. Try to run
python manage.py clearsessions
I've been developing a couple of applications inside a Django CMS installation and have found it caches things well against my orders. This might not be such an issue in production but while I'm testing layouts, having to wait 10 minutes (or restart memcache) gets pretty boring.
Can I disable Django CMS's caching globally in my development settings?
Set the following settings locally:
CMS_PAGE_CACHE = False
CMS_PLACEHOLDER_CACHE = False
CMS_PLUGIN_CACHE = False
If it still caches after that, then it could be a bug..
I've just started a new django project, didn't change settings to much. And my admin session cookie is expired in seconds (I've checked in the DB as well.)
I've tried setting this:
SESSION_COOKIE_AGE = 1209600
which is the default setting, but it does not work. Why this is happening?
I must say it didn't occur in other django project I have.
I have a bit weird problem witch caching on my project in django.
I can edit my page-content in django-admin. When i do that and refresh site - nothing is happening. I have to wait few minutes for changes. Funny thing is that, when i change browser (or computer) - i dont have to wait - the changes are on. Is it the problem of django, browser or what? Is it possible to set setting.py to get changes immediately?
By the way, i have already figured out that when i turn the "django.middleware.cache.FetchFromCacheMiddleware" off - the problem disapears, but i dont want to turn cache off...
Any ideas?
When you have cache middleware enabled, Django caches the rendered template. When the next request is made, Django checks the cache for the template, and if it exists, it returns a 304 Not Modified rather than the normal 200 Found HTTP response. That tells your browser to pull it from its cache instead of pulling it down from the server again. (It's a lot more complicated than this in practice, but I'm simplifying).
Long and short, is this is how caching in Django works. If you don't want this behavior, then you can either disable the cache (not the cache middleware), by telling it to use the DummyCache backend:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
This will result in Django always returning a 200 with a fresh copy because it can never find the cached copy. You can also add the following setting to settings.py:
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
Then, if you're logged in (through admin or otherwise), the response will vary on that and always return a fresh copy. However, this will effect normal users of your site as well, if you have any public-facing login capability.
I've written a django application, and put it on a CentOS server. It is definitely okay when I use django development web server.
Such as I start it by "python ./manage.py runserver", and access that server from browser on another computer. I can sign in one time, and access all the pages without issues.
However when I run it with apache+mod_wsgi, I just found I have to login with user and password time by time. I think maybe there is some problem with the session middleware, so, how can I find the root cause and fix it?
There are a couple of different options for this.
In order of likelyhood (imho):
The session backend uses the cache system to store the sessions and you're using the locmem cache backend
The session backend isn't storing the cookies (secure cookies enabled? cookie timeouts? incorrect date on the server?)
The session middleware might not be loaded (custom settings for production server?)
Storing the session in the cache is only a good solution if you use memcached as the cache backend. So if you're storing the sessions in cache, make sure you use memcache :)
Either way, check if SESSION_ENGINE is set to django.contrib.sessions.backends.db