python - django 缓存 session 的登录问题

标签 python django session caching

我在使用 django 的缓存后端时遇到问题

SESSION_ENGINE = "django.contrib.sessions.backends.cache"

当我将 session 引擎设置为使用缓存而不是数据库时。我无法登录。从应用程序日志中我可以看到身份验证成功,响应还包含 session_id 的 set-cookie header 。所以这一切似乎都在起作用。除了我登录后刚刚返回到登录页面。我猜这个 session

如果我注释掉 session 引擎,它会恢复使用数据库 session 引擎并按预期工作。

这在我的 python 2.7 机器上本地工作,在这不起作用的服务器上正在运行 python 2.6 (我不确定这是否相关,但这是我能找到的唯一真正的区别)。 pip 包大部分是相同的,我认为这一切都来自 django 内部。 我在这两个地方都使用 django 1.6.7。

最佳答案

LocMemCache 不适合生产。

You should only use cache-based sessions if you’re using the Memcached cache backend. The local-memory cache backend doesn’t retain data long enough to be a good choice, and it’ll be faster to use file or database sessions directly instead of sending everything through the file or database cache backends. Additionally, the local-memory cache backend is NOT multi-process safe, therefore probably not a good choice for production environments.

https://docs.djangoproject.com/en/1.6/topics/http/sessions/#using-cached-sessions

通常,当我第一次部署时,我会从配置的数据库缓存开始,只是为了证明配置。然后切换到 Memcache 或 Redis。

关于python - django 缓存 session 的登录问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29676360/

相关文章:

django - 如何检查 Django 表单是否已保存以显示适当的反馈?

java - Struts 2 session 值未反射(reflect)在负载平衡环境/域 URL 中的 JSP 中

php - APC 开启时的 session 问题

Python 3 正在将元素添加到列表中,而不管 dict 中使用的键是什么

python - 如何从嵌套列表中删除循环(无穷大)符号?

mysql - Django:存储在 MySQL 数据库中的时区不正确

Django 重组没有按预期工作

php - 如何使登录页面 PHP 与 Session 一起工作。

python - 在我的 SQL SELECT 语句中使用通过 Bottle 路由传递的参数

python - 有人可以解释一下 Scikit-learn 中的 MaxAbsScaler 吗?