First time here? Check out the FAQ!

For Discussion: Updating Askbot for USE_TZ=True in Django>=1.4

I've been working on integrating Askbot with a commercial product developed in Django 1.5.8. A major sticking point I ran into was the use of timezone-aware datetime objects in the existing product, which cause the "Can't subtract offset-naive and offset-aware datetimes" exception. (I can't post links, but search for it on this forum, and you'll find at least one thread.)

I've created a fix. It was a basically a find-and-replace operation, replacing all instances of in the code with, and adding an import: from django.utils import timezone. is a Django utility function that returns a timezone-aware or timezone-naive datetime object according to the USE_TZ setting. I also had to update some datetime.datetime instances with a tzinfo attribute, and I had to replace import datetime in all migration scripts with from south.utils import datetime_utils as datetime, which is a South compatibility layer for USE_TZ.

I could contribute this fix back, but it would force dependency updates. Django's timezone module was introduced in Django 1.4, so versions of Django<1.4 would no longer be compatible with Askbot. Versions of South before datetime_utils was introduced would also no longer be compatible. It would be possible to write compatibility patches, eg:

    from django.utils import timezone
except ImportError:
    from askbot.utils import timezone

...but I'm hesitant to do so, because a lot of the work I've had to do in getting Askbot to work in Django 1.5.8 has been undoing or working around prior patches. I would rather contribute work that moves Askbot forward.

geekofalltrades's avatar
asked 2014-08-14 11:35:13 -0500
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

1 Answer


The issue is that USE_TZ = True makes local time rendered in the html templates, essentially "personalizing" the pages per timezone. This makes it harder to cache template fragments.

Local time can be rendered by Javascript based on the UTC timestamps as we have now or a reference time zone. If there is a way to make timestamp display in Askbot independent on the USE_TZ setting and allow the integrators make their own choice of that setting - it might be worth getting that done.

Evgeny's avatar
answered 2014-08-15 02:24:02 -0500, updated 2014-08-15 02:25:28 -0500
edit flag offensive 0 remove flag delete link


add a comment see more comments