The Canvas of Ryan Sadwick

Django: can't compare offset-naive and offset-aware datetimes error

Use utc instead.

Django: can’t compare offset-naive and offset-aware datetimes error

May. 1st | Posted by 20 comments

I was testing out django-registration, a simple login system that has a few features: forgot password, activation email. I ran into an error while firing up the admin: can’t compare offset-naive and offset-aware datetimes error with Django-registration. There is logic in this package where it records the user’s creation date and last login date. The dates in the admin tool are specified to be UTC. (Django 1.4) However the package doesn’t use UTC, it uses native.

You’ll need to fix that in django-registration’s model… OR grab the latest build from bitbucket.

I found a fix here, where the model.py is fixed to use:

(self.user.date_joined + expiration_date <= datetime.datetime.utcnow().replace(tzinfo=utc))

Check out the easy steps to implement this fix (why not just grab the new code?) here:
http://spottedsun.com/django-registration-activation-error-for-django-1-4/


20 comments Add a comment


Comments are closed.