Форум сайта python.su
Настроил i18n. Все работает нормально, но вот столкнулся с проблемой.
Делаю логаут пользователя:
def logout_view(request):
logout(request)
return HttpResponseRedirect('/')
Офлайн
Может потому что, когда юзер активный, то в сессии сохраняются его настройки. А когда логаут, то сессия юзера удаляется, и тогда все настройки обнулются.
Update: Все дело а HttpResponseRedirect(). Не пойму, как по другому сделать редирект.
Отредактировано (Фев. 2, 2010 13:57:32)
Офлайн
Ну, нашел решение. Взял с django.views.i18n
Вот, что вышло:
def logout_view(request):
next = request.META.get('HTTP_REFERER', None) or '/'
response = HttpResponseRedirect(next)
logout(request)
lang_code = request.LANGUAGE_CODE
if lang_code and check_for_language(lang_code):
if hasattr(request, 'session'):
request.session['django_language'] = lang_code
else:
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
return response
Отредактировано (Фев. 2, 2010 14:46:32)
Офлайн
А ответ один:
Changed in Django 1.0: Calling logout() now cleans session data.Просто сохраняйте установленный язык в переменной, и устанавливайте его в сессию после того, как пользовать разлогинится.
When you call logout(), the session data for the current request is completely cleaned out. All existing data is removed. This is to prevent another person from using the same web browser to log in and have access to the previous user's session data. If you want to put anything into the session that will be available to the user immediately after logging out, do that after calling django.contrib.auth.logout().
Офлайн