A
A
Andrey Salnikov2017-07-20 09:24:51
Django
Andrey Salnikov, 2017-07-20 09:24:51

Is it possible to have the same sessions on two sites?

The hosts file is set to:
127.0.0.1 one.ru
127.0.0.1 two.ru I start
the project:
python manage.py runserver 80
Both sites are successfully picked up and working.
Created MIDDLEWARE:

from django.urls import set_urlconf

class SimpleMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.
        host = request.get_host()
        if host == 'one.ru':
            set_urlconf('one.urls')
            request.urlconf = 'one.urls'
        elif host == 'two.ru':
            set_urlconf('two.urls')
            request.urlconf = 'two.urls'
        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.
        host = request.get_host()

        return response

Each of the sites gives its data.
There was a following problem - Sessions are not saved.
In View, I write On the site, this is immediately displayed in the template, but as soon as this line is removed, it disappears from the template. Questions: 1) Why is this happening? 2) Is it possible to make identical sessions on two sites this way?
request.session.q = 5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PrAw, 2017-07-20
@Shshzik

Both sites should store sessions together and transfer you to each other (additional cookie, intermediary service). It is similarly implemented here - transparent authorization through TM
If they simply store session files in a shared storage - when visiting sites - 2 different sessions will be generated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question