문제

I am setting a session variable in my Django application, like this:

request.session['something'] = True

After this, I am redirecting the user to Login (via facebook - django-social-auth). After the user is successfully logged in, my session variable is lost. I know this because:-

if "something" in request.session -- is returning False

Does Django flush the session object on login/logout (using the Django Authentication System) or am I doing something wrong?

도움이 되었습니까?

해결책

According to the login source code:

def login(request, user):
    """
    Persist a user id and a backend in the request. This way a user doesn't
    have to reauthenticate on every request. Note that data set during
    the anonymous session is retained when the user logs in.
    """

So, if you set something in the anonymous request.session it will be there after logging in.

login flushes the session only if the existing session corresponds to a different authenticated user.

logout always flushes the session (source code).

Hope that helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top