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. Both projects and both applications have the same name, for example myproject.myapplication. They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../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.


Asked by: Aida596 | Posted: 28-01-2022






Answer 1

Set the SESSION_COOKIE_DOMAIN option. You need to set the domain for each of your sites so the cookies don't override each other.

You can also use SESSION_COOKIE_NAME to make the cookie names different for each site.

Answered by: Elian917 | Posted: 01-03-2022



Answer 2

I ran into a similar issue with a live & staging site hosted on the same Apache server (on 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. I also ran "python manage.py cleanup" to (hopefully) clean any conflicted information out of the database.

Answered by: Chester803 | Posted: 01-03-2022



Answer 3

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. You have to use different project names that will go in different MySQL (or whatever) databases.

Answered by: Andrew149 | Posted: 01-03-2022



Answer 4

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.

Answered by: Alissa219 | Posted: 01-03-2022



Answer 5

Let me guess, is this running on your localhost? and you have each site assigned to a different port? i.e. localhost:8000, localhost:8001 ..?

I've had the same problem! (although I wasn't running Apache per se)

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.

When you visit the other site, the server tries to interpret the cookie, but fails. I'm guessing it deletes the cookie because it's "garbage".

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. this way the second site doesn't attempt to read the cookie that was set by the first site

I also think you can edit your HOSTS file to add more aliases to 127.0.0.1 if you need to. (but I haven't tried this)

Answered by: Carlos925 | Posted: 01-03-2022



Similar questions





Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top