A
A
Andrey Salnikov2017-07-19 15:57:09
Django
Andrey Salnikov, 2017-07-19 15:57:09

How to use sessions across two sites in django?

There are 2 sites.
The site structure is as follows:

env ( Окружение )
one ( основная папка проекта )
-manage.py ( файл управления первого сайта )
-manage_another.py ( файл управления второго сайта )
-one
--settings_all.py ( Файл настроек с общими настройками для обоих сайтов )
--settings.py ( Файл настроек первого сайта )
--settings_another.py ( Файл настроек второго сайта )
--wsgi.py ( wsgi первого сайта )
--wsgi_another ( wsgi второго сайта )

These two sites have the same database.
I run 2 instances of runserver:
python manage.py runserver (For the first site)
python manage_another.py runserver 127.0.0.2:8000 (for the second site)
How can I make the same sessions and cookies between these two sites on 1 database? This is necessary to implement a common account on these sites.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Kuzmichev, 2017-07-20
@Shshzik

Two sites on different domains cannot see each other's cookies (the browser simply will not send other people's cookies), and accordingly, the session cannot be divided either.
If there are resources to do everything well, then you can get confused with OAuth2. This protocol, roughly speaking, allows you to log in to one of the sites using another. For example, this is how social network authorization works throughout the Internet. There is a nice django-allauth library that supports authorization for a lot of providers.
If the use of any social network does not suit you (that is, you yourself want to act as a provider), then in your case I see 2 options:

  • log in to one of these two sites using the second. That is, one of the sites will be an OAuth2 provider
  • the same, but make a separate project for this (which will be the OAuth2 provider), purely for authorization on your two sites. This is how TM projects work, for example: for authorization on the sites habrahabr.ru, geektimes.tu, toster.ru, etc. id.tmtm.ru is used

D
Dimonchik, 2017-07-19
@dimonchik2013

cookie depends on the domain, what's the point that it will be the same for another?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question