-1

I am working on 2 Django app which is running on ports - 8001 and 8002. But the problem is when I click on any link on the second app, the first app make me log out and when I log in to the first one, the second app makes me log out.

Is there any session conflict? Can anyone suggest me how to solve this?

Aniket Singh
  • 2,464
  • 1
  • 21
  • 32

1 Answers1

1

Yes, there's a session conflict. Cookies aren't port-specific, i.e., server running on port A can read and write cookies set by a server running on port B, if both are on the same domain.

Since Django uses the name called sessionid for session cookies, both your django apps (I think you meant projects?) are overwriting this cookie.

However, Django allows you to use specific name for the session cookie using SESSION_COOKIE_NAME setting. So you can change one project's cookie name.

SESSION_COOKIE_NAME = 'sessionid_project1'

And you may also want to rename the csrf cookie using CSRF_COOKIE_NAME setting to avoid conflict there as well.

xyres
  • 20,487
  • 3
  • 56
  • 85