RuntimeWarning: DateTimeField received a naive datetime

I m trying to send a simple mail using IPython. I have not set up any models still getting this error. What can be done?

Error : /home/sourabh/Django/learn/local/lib/python2.7/site-packages/django/db/models/fields/ init .py:827: RuntimeWarning: DateTimeField received a naive datetime (2013-09-04 14:14:13.698105) while time zone support is active. RuntimeWarning)

Tried : The first step is to add USE_TZ = True to your settings file and install pytz (if possible).

Error changed:

(learn)sourabh@sL:~/Django/learn/event$ python manage.py shell
/home/sourabh/Django/learn/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:53: RuntimeWarning: SQLite received a naive datetime (2013-09-05 00:59:32.181872) while time zone support is active.
  RuntimeWarning)

The problem is not in Django settings, but in the date passed to the model. Here's how a timezone-aware object looks like:

>>> from django.utils import timezone
>>> import pytz
>>> timezone.now()
datetime.datetime(2013, 11, 20, 20, 8, 7, 127325, tzinfo=pytz.UTC)

And here's a naive object:

>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2013, 11, 20, 20, 9, 26, 423063)

So if you are passing email date anywhere (and it eventually gets to some model), just use Django's now() . If not, then it's probably an issue with an existing package that fetches date without timezone and you can patch the package, ignore the warning or set USE_TZ to False.


这里是关于你面对时区和灯具的问题的文档


使用django.utils.timezone.make_aware函数使您的天真日期时间对象能够识别时区,并避免出现这些警告。

链接地址: http://www.djcxy.com/p/38668.html

上一篇: django queryset过滤器datetimefield

下一篇: RuntimeWarning:DateTimeField收到一个天真的日期时间