早期 Django 管理员注销
我正在开发一个 Django 1.2.3 项目,我发现管理会话似乎在登录后大约一分钟后就超时了,甚至在我使用它时也是如此。
最初,我有这些设置:
SESSION_COOKIE_AGE=1800
SESSION_EXPIRE_AT_BROWSER_CLOSE=True
我认为问题可能是我的会话存储配置错误,因此我尝试通过添加以下内容将我的会话配置为存储在本地内存中:
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
CACHE_BACKEND = 'locmem://'
但是,问题仍然发生。即使用户处于活动状态,是否还有其他原因会导致管理会话提前超时?
I'm working on a Django 1.2.3 project, and I'm finding that the admin session seems to timeout extremely early, after about a minute after logging in, even while I'm using it.
Initially, I had these settings:
SESSION_COOKIE_AGE=1800
SESSION_EXPIRE_AT_BROWSER_CLOSE=True
I thought the problem might be my session storage was mis-configured, so I tried configuring my session to be stored in local memory by adding:
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
CACHE_BACKEND = 'locmem://'
However, the problem still occurs. Is there something else that would cause admin sessions to timeout early even when the user is active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 locmem:// 中缓存会话意味着每当 python 进程重新启动时您都会丢失会话。如果您在开发服务器下运行,那么这就是您保存文件的任何时间。在生产环境中,这会根据您的基础设施而有所不同 - 例如,apache 中的 mod_wsgi 将在一定数量的请求后重新启动 python(这是高度可配置的)。如果您配置了多个 python 进程,那么只要您的请求转到不同的进程,您就会丢失会话。
更重要的是,如果生产环境中有多个服务器,locmem:// 将仅引用一个服务器进程。
换句话说,不要使用 locmem:// 进行会话存储。
Caching sessions in locmem:// means that you lose the session whenever the python process restarts. If you're running under the dev server, that would be any time you save a file. In a production environment, that will vary based on your infrastructure - mod_wsgi in apache, for example, will restart python after a certain number of requests (which is highly configurable). If you have multiple python processes configured, you'll lose your session whenever your request goes to a different process.
What's more, if you have multiple servers in a production environment, locmem:// will only refer to one server process.
In other words, don't use locmem:// for session storage.