我有一个我在Django 1.6中构建的博客系统,我正在尝试使用Post模型的DateTimeField,pub_date渲染YearArchiveView,或者至少获得一些带有帖子的列表。它一直告诉我我的pub_date是天真的,但我明确地改变了它们不是。
这是我在python shell上做的一些推特:
>>> for post in posts:
... post.pub_date
...
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
>>> years = Post.live.datetimes('pub_date', 'year', order='DESC')
/Users/.../django/db/models/fields/__init__.py:903: RuntimeWarning: DateTimeField Post.pub_date received a naive datetime (2014-01-13 21:40:01.051109) while time zone support is active.
RuntimeWarning)
>>> years
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/.../django/db/models/query.py", line 71, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/Users/.../db/models/query.py", line 96, in __iter__
self._fetch_all()
File "/Users/.../django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/.../django/db/models/sql/compiler.py", line 1107, in results_iter
raise ValueError("Database returned an invalid value "
ValueError: Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
>>> import pytz
>>> posts[0].posted
datetime.datetime(2013, 9, 26, 0, 48, 8, tzinfo=<UTC>)
>>>
到底是怎么回事?我疯了!