简体   繁体   English

一个Apache上的多个Django管理站点...当我登录一个时,我会从另一个登录

[英]Multiple Django Admin Sites on one Apache… When I log into one I get logged out of the other

I have two Django projects and applications running on the same Apache installation. 我有两个Django项目和应用程序在同一个Apache安装上运行。 Both projects and both applications have the same name, for example myproject.myapplication. 项目和两个应用程序都具有相同的名称,例如myproject.myapplication。 They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../dir2/myproject/myapplication. 它们分别位于单独命名的目录中,因此它看起来像... / dir1 / myproject / myapplication和... / dir2 / myproject / myapplication。

Everything about the actual public facing applications works fine. 关于实际面向公众的应用程序的一切工作正常。 When I log into either of the admin sites it seems ok, but if I switch and do any work on the opposite admin site I get logged out of the first one. 当我登录任何一个管理站点时,它似乎没问题,但如果我切换并在对方管理站点上做任何工作,我将退出第一个。 In short I can't be logged into both admin sites at once. 简而言之,我无法立即登录这两个管理站点。 Any help would be appreciated. 任何帮助,将不胜感激。

Set the SESSION_COOKIE_DOMAIN option. 设置SESSION_COOKIE_DOMAIN选项。 You need to set the domain for each of your sites so the cookies don't override each other. 您需要为每个站点设置域,以便cookie不会相互覆盖。

You can also use SESSION_COOKIE_NAME to make the cookie names different for each site. 您还可以使用SESSION_COOKIE_NAME为每个网站设置不同的Cookie名称。

I ran into a similar issue with a live & staging site hosted on the same Apache server (on CentOS). 我在同一个Apache服务器(在CentOS上)托管的实时和暂存站点遇到了类似的问题。 I added unique SESSION_COOKIE_NAME values to each site's settings (in local_settings.py, create one if you don't have one and import it in your settings.py), set the SESSION_COOKIE_DOMAIN for the live site and set SESSION_COOKIE_DOMAIN = None for staging. 我为每个网站的设置添加了唯一的SESSION_COOKIE_NAME值(在local_settings.py中,如果没有,则创建一个并在settings.py中导入),为实际网站设置SESSION_COOKIE_DOMAIN并为暂存设置SESSION_COOKIE_DOMAIN =无。 I also ran "python manage.py cleanup" to (hopefully) clean any conflicted information out of the database. 我还运行“python manage.py cleanup”来(希望)清除数据库中的任何冲突信息。

Well, if they have the same project and application names, then the databases and tables will be the same. 好吧,如果他们有相同的项目和应用程序名称,那么数据库和表将是相同的。 Your django_session table which holds the session information is the same for both sites. 保存会话信息的django_session表对于两个站点都是相同的。 You have to use different project names that will go in different MySQL (or whatever) databases. 您必须使用不同的MySQL(或其他)数据库中的不同项目名称。

The session information is stored in the database, so if you're sharing the database with both running instances, logging off one location will log you off both. 会话信息存储在数据库中,因此如果您与两个正在运行的实例共享数据库,则注销一个位置将使您同时注销。 If your circumstance requires you to share the database, the easiest workaround is probably to create a second user account with admin privileges. 如果您的情况需要您共享数据库,最简单的解决方法可能是创建具有管理员权限的第二个用户帐户。

Let me guess, is this running on your localhost? 让我猜一下,这是在你的本地主机上运行吗? and you have each site assigned to a different port? 并且您将每个站点分配到不同的端口? ie localhost:8000, localhost:8001 ..? 即localhost:8000,localhost:8001 ..?

I've had the same problem! 我遇到了同样的问题! (although I wasn't running Apache per se) (虽然我本身并没有运行Apache)

When you login to the admin site, you get a cookie in your browser that's associated with the domain "localhost", the cookie stores a pointer of some sort to a session stored in the database on the server. 当您登录管理站点时,您在浏览器中获得与域“localhost”相关联的cookie,cookie会将某种指针存储到服务器上数据库中存储的会话中。

When you visit the other site, the server tries to interpret the cookie, but fails. 当您访问其他站点时,服务器会尝试解释cookie,但会失败。 I'm guessing it deletes the cookie because it's "garbage". 我猜它会删除cookie,因为它是“垃圾”。

What you can do in this case, is change your domain 在这种情况下,您可以做的是更改您的域名

use localhost:8000 for the first site, and 127.0.0.1:8001 for the second site. 第一个站点使用localhost:8000,第二个站点使用127.0.0.1:8001。 this way the second site doesn't attempt to read the cookie that was set by the first site 这样,第二个站点不会尝试读取第一个站点设置的cookie

I also think you can edit your HOSTS file to add more aliases to 127.0.0.1 if you need to. 我还认为如果需要,您可以编辑HOSTS文件以向127.0.0.1添加更多别名。 (but I haven't tried this) (但我没试过这个)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以通过一个 django 安装来托管多个站点吗 - Can i host multiple sites with one django installation 如何在一台服务器上的多个站点中使用Django中的多个设置文件? - How do I use multiple settings file in Django with multiple sites on one server? 我必须在python中一个一个打开多个站点 - I have to open multiple sites one by one in python 跨多个Django站点的Django一个用户 - Django one user across multiple django sites 从管理员注销时,Django CMS占位符内容未显示在页面上 - Django CMS placeholder content not showing up on page when i log out from the admin 每次用户在 Django 中登录和注销时,如何登录? - How can I log every time a user has logged in and logged out in Django? “ django.contrib.admin.sites.NotRegistered:未注册模型用户”想要注册我的自定义用户时出现此错误。 - “django.contrib.admin.sites.NotRegistered: The model User is not registered” I get this error when a want to register my Custom User. 我登出后如何在Django中呼叫预设的首页网址 - How to Call default home url in django when i logged out Django:具有多种网站和语言的管理员 - Django: Admin with multiple sites & languages Django中的模型,当我在admin中编辑一个时如何更改两个值? - model in django,how to change two value when I edit one in admin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM