diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-11-22 15:31:31 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-11-22 15:34:37 +0100 |
| commit | 9f8810ac51afe7eda276ca54a46cb49fb23c1d5a (patch) | |
| tree | 263aadb79faa801f5cef79a672d9e60fe02b2be6 | |
| parent | 4a54b69e8829fd3e7994f5248c4711c4f594e8a5 (diff) | |
Fixed #21487 -- Session cannot store tzinfo instances anymore.
Thanks filipp for the report.
Forward-port of 1eddca0a from stable/1.6.x.
| -rw-r--r-- | docs/topics/i18n/timezones.txt | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/docs/topics/i18n/timezones.txt b/docs/topics/i18n/timezones.txt index 4652e7e9c1..5e3a482154 100644 --- a/docs/topics/i18n/timezones.txt +++ b/docs/topics/i18n/timezones.txt @@ -184,24 +184,25 @@ error handling entirely for the sake of simplicity.) Add the following middleware to :setting:`MIDDLEWARE_CLASSES`:: + import pytz + from django.utils import timezone class TimezoneMiddleware(object): def process_request(self, request): - tz = request.session.get('django_timezone') - if tz: - timezone.activate(tz) + tzname = request.session.get('django_timezone') + if tzname: + timezone.activate(pytz.timezone(tzname)) else: timezone.deactivate() Create a view that can set the current timezone:: - import pytz from django.shortcuts import redirect, render def set_timezone(request): if request.method == 'POST': - request.session['django_timezone'] = pytz.timezone(request.POST['timezone']) + request.session['django_timezone'] = request.POST['timezone'] return redirect('/') else: return render(request, 'template.html', {'timezones': pytz.common_timezones}) |
