Setting current timezone in Django 1.4, and middleware

177 views
Skip to first unread message

peppergrower

unread,
May 9, 2012, 1:20:40 PM5/9/12
to django...@googlegroups.com
In 1.4, what exactly is the scope of the current timezone? In other words, if I use activate() to set a current timezone, is that global? Or does it only apply to the current request (and not persist across requests)? Or, some other scope? (I looked at the source and it appears that it might apply to the current thread, but I'm not familiar with how Django uses threads, so I don't know how that affects the answer.)

I've read the documentation here, and it doesn't really state the scope, as far as I can tell. However, the suggestion to create middleware to handle it is interesting; is this the recommended way to deal with timezones when serving users with a variety of preferred timezones?

peppergrower

unread,
May 10, 2012, 4:39:35 PM5/10/12
to django...@googlegroups.com
I set up a fresh Django 1.4 project and adapted the middleware described in the docs; I stored the timezone on the user profile of two different users, and logged in as each of them in separate browsers, along with a third completely separate window (so I had three different sessions). It appears that activate() only persists in a given request/response cycle; it didn't bleed through to the unauthenticated window, which wasn't setting its own timezone. So something like the middleware in the docs will work nicely for my uses, I think.
Reply all
Reply to author
Forward
0 new messages