会话在本地主机上的两个Flask应用之间共享 [英] Session is shared between two Flask apps on localhost
问题描述
因此,我有两个在本地主机上运行的Flask应用程序,一个在端口5001上运行,另一个在端口5003上运行,显然两者都使用相同的会话.如果我登录一个应用程序,则退出另一个应用程序.例如,最近,如果我在一个应用程序上使用电子邮件登录,它也会在另一个应用程序上登录我的帐户,因为我有用户在两个应用程序上都使用该电子邮件,并且我将电子邮件用作用户标识,但是当我为用户使用另一个ID时,这种情况就停止了.
So, I have two Flask apps running on localhost, one on the port 5001, and the other one on the port 5003, and apparently both are using the same session. If I log in on one app, it logs out on the other. And for example, recently, if I logged in using my email on one app, it would also log in my account on the other app, since I have users using that email on both apps, and I was using the email as an user identifier, but that stop happening when I used another id for the users.
我正在使用Flask-Login和Google Chrome(在Edge中也是如此).
I'm using Flask-Login, and Google Chrome (the same thing happens in Edge).
我不确定这是否还会在生产环境中发生,我们可能会在两个应用程序中使用相同的主机,所以这将是一个问题.如果这仅与本地主机相关,则可以,但我认为不是这种情况.
I'm not really sure if this could also happen in production, we'll probably use the same host for both apps, so that would be a problem. If this is something related only to localhost, then it's ok, but I don't think that's the case.
有什么想法在这里发生吗?
Any idea of what could be happening here?
谢谢.
推荐答案
我有一个类似的问题,我认为原因是两个实例在浏览器中将使用相同的会话cookie".
I had a similar problem, and I think the cause is that both instances would use the same "session cookie" in the browser.
为我修复的解决方案是重命名默认为session
的SESSION_COOKIE_NAME
.
The solution that fixed it for me was renaming the SESSION_COOKIE_NAME
which is session
by default.
app.config.update(SESSION_COOKIE_NAME=<new_session_name>)
我通过以下方式找到了解决方案: https://stackoverflow.com/a/45497948/380038
I found the solution via: https://stackoverflow.com/a/45497948/380038
这篇关于会话在本地主机上的两个Flask应用之间共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!