Django session periodically disappears right after login

In my django app, I am handling login like this. Users go to the gateway page (index.html) - if they are not already logged in, a login / password form will exist along with other stuff. On successful login (or if they otherwise navigate to this page during login), the page is displayed slightly differently (no login form).

How I handle this in the view for index.html:

logged_in = request.user.is_authenticated()

      

and then the variable logged_in

is passed to the template, which is checked to see which version of the page it displays.

When the user logs in, the login window opens:

user = authenticate(username=username, password=password)
if user is not none:
    login(request, user)

      

And then they are redirected back to index.html.

More often than not, this works fine. However, I see that sometimes between the HttpResponseRedirect

and the index it can be seen that request.user has been destroyed. I have been logging this for a while now, logging as the last item in the login window and the first item in the index view. The effect it has on the user is that it looks like they are not logged in correctly (except for the message that no message has been reported).

He seems to come with hostility, since the system will be good for a while, and then I will see that this happens to the user 4-5 times in a row. I should also point out that I have never seen / heard of this at any point other than when logging in, as far as I can tell (it is possible that this happened and no one complained) when they are, they 'in in.

Am I doing something clearly wrong with my login methodology here?

+2


source to share


1 answer


Apache + Mod Python or WSGI use threads and can pre-cache your requests (depends on your conf). Therefore, if you have changed something in the code, you need to restart the apache. then the problem should go away.



+1


source







All Articles