How to share a session between two django applications?

I have two django applications that are on the same server on port 80and 9002. i.e. urls www.abc.comand www.abc.com:9002 Both use the same postgresql database for authentication. I want to share with the session data between them, so that a user registered in one application can automatically register in another application.

I read the following answers: Multiple Django applications, general authentication and How to get separate Django applications on the same session cookie subdomain?

And did it in my django application:

  • The same secret key is used in both.
  • The following lines are added:

    SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' SESSION_COOKIE_NAME = 'abc'
    SESSION_COOKIE_DOMAIN = '.abc.com'

But still, I cannot achieve this goal. How to share a session cookie between two django applications so that I can have general authentication?

+8
source share
1 answer

Besides applying these settings to both applications, the only thing missing in your approach is SESSION_COOKIE_DOMAIN.

You install it on ".abc.com", which means that it will work if your application has a domain name: www.abc.comand somesubdomain.abc.com.

www.abc.com:9002, , TLD www.abc.com. , django , www.abc.com:9002 www.abc.com - , .abc.com.

, :

  1. django. Django , ROOT_URL_CONF DJANGO_SETTINGS_MODULE , . , .

  2. -, nginx haproxy, , . , , django, first.abc.com second.abc.com ( 80 second.abc.com ), . , , .

. ALLOWED_HOSTS .abc.com .

0

All Articles