I am almost beginner in django, the problem i am facing is that when i logged in main site from an account and then logged into admin site from admin's account then this admin automatically logged into the main site ,and the already logged in user of the main site,i have no idea where he disappear...the problem i face only if i logged into both accounts on same browser, if I open them on different browsers then it works properly, Is it related to session? can you please tell me what is this issue and how can I solved.

i want that when i logged into the admin site ,the admin wouldn't logged into the main site,

1

There are 1 best solutions below

0
v25 On

The problem is the cookie is domain specific, so if you're accessing the whole site on http://localhost:8000 (for example) authenticating as another user then changes the cookie for that entire domain (localhost).

How to solve this depends on your objectives. This thread discusses some methods but each with their own complexity and shortfalls.

If loading the main site in your normal browser, and the admin site in a private tab isn't suitable (this would work because each has different cookie storage) then you could possibly create a host entry if it's just for development on a local machine.

Add a host entry like:

127.0.0.1 admin.localhost

...to the file c:\Windows\system32\drivers\etc\hosts or if you're using Linux or Mac the file /etc/hosts.

Then tell Django to accept connections with this Host header, by editing the line in your settings.py to include the new host:

ALLOWED_HOSTS = ['localhost', 'admin.localhost']

Now retry in your browser, accessing the admin site via http://admin.localhost:8000/ and it should work, without the need for a private tab.