나는 장고 1.6에 구축하고있는 블로그 시스템을 가지고 있으며, YearArchiveView를 렌더링하려고하거나 적어도 Post 모델의 DateTimeField, pub_date에서 몇 년 간의 게시물 목록을 얻고있다. 내 pub_date가 순진하다는 것을 계속 알려주지 만 명시 적으로 변경하지 않았습니다.Django가 내 datetimes를 순진하게 호출하지 않는 이유는 무엇입니까?
>>> 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>)
>>>
도대체 무슨 : 여기
내가 파이썬 쉘에서 수행 한 몇 가지 puttering입니까? 내가 미친거야!
디버깅에 대한 몇 가지 세부 정보를 제공해 주시겠습니까? 'datetimes()'질의에 대해 생성 된 SQL은 무엇입니까? 'str (Post.live.datetimes ('pub_date', 'year', order = 'DESC'). query)'를 실행할 수 있습니다. 또한, 생성 된 SQL을 MySQL에 직접 연결하고 어떤 유형의 결과가 반환되는지 확인하려고합니다. –