Thursday, June 5, 2014

Re: Django Login/Session Not Sticking

PLEASE HELP: I am not sure if this is a bug or caused by my code. But this is a serious issue for my production site.


To get some more debug information, I have created this Middleware:


from django.conf import settings

class SessionDebugMiddleware(object):
    def process_response(self, request, response):
            session = request.session
            user = getattr(request, 'user', None)
            if user:
                user=user.id
            session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
            response['X-Meta-Requ'] = '{0},{1},{2},{3}'.format(session_key, session.get('_auth_user_id'), session.get('_auth_user_backend','---'), user)
            return response


If I hit the refresh button 10 times, 
8 times I will get this header:  X-Meta-Requ:igv0xshezhdxh50kks9x00r0l67mx0sk,None,---,None
2 times I will get this header: X-Meta-Requ:igv0xshezhdxh50kks9x00r0l67mx0sk,330619,django.contrib.auth.backends.ModelBackend,330619

It seems be be random and does not follow any logic.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/13b90bb8-7497-4a49-82e5-0a478ca1d1de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment