views:

93

answers:

2

When I use Django's logout function to log out an authenticated user, it switched locale to en_US, the default one.

from django.contrib.auth import logout

def someview(request):
    logout(request)
    return HttpResponseRedirect('/')

How to keep user's locale after logged out?

A: 

You can create a UserProfile model (that has unique foreign key to User) and save the user's language preference there (and any other extra user specific setting). Then on every user login, the locale can be set to the language code saved in the user's UserProfile.

Django has a setting AUTH_PROFILE_MODULE, where you can set a model as an "official" user profile model for django.contrib.auth

Béres Botond
I'm not entirely sure that that would work when the user is logged _out_ but defintely when they are logged _in_
NeonNinja
The user profile wont help after users logged out.
jack
+1  A: 

You could try explicitly setting the language cookie when the user logs out, there's a bit about how django determines the language setting here in the djangodocs.

I would have presumed that the language setting would have remained as a session value on logging out, maybe it needs to be reinitialised if django completely destroys the session on logging out the user.

NeonNinja