django中的运行时警告 [英] Runtime Warning in django
问题描述
我正在使用MySQL作为后端的Django项目,这个警告一直困扰着我,任何人都可以为此建议一个修复。感谢提前!!
/usr/local/lib/python2.7/dist-packages/django/db/models/字段/ __ init__.py:808:
RuntimeWarning:DateTimeField在时区支持处于活动状态时收到了一个天真的datetime(2013-04-22 10:34:44)
。
您必须进行以下更改:
在settings.py中,您需要添加以下行:
USE_TZ = True
此外,在代码中,您应该创建意识
datetime对象:
例如:
而不是
import datetime
now = datetime.datetime.now()
您应该执行以下操作:
from django.utils.timezone import now
now_time = now()
这将使用US $ _ $ c> settings.py ,并创建感知
datetime对象,而不是 native
。 p>
您应阅读 https: //docs.djangoproject.com/en/dev/topics/i18n/timezones/
I am working on a Django project with MySQL as the back-end, this warning keeps troubling me, can anyone please suggest a fix for this. Thanks in advance!!
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808:
RuntimeWarning: DateTimeField received a naive datetime (2013-04-22 10:34:44)
while time zone support is active.
You have to make the following changes:
In settings.py, you need to add following line:
USE_TZ = True
Also, in your code you should create aware
datetime objects:
eg:
Instead of
import datetime
now = datetime.datetime.now()
You should do:
from django.utils.timezone import now
now_time = now()
This will make use of USE_TZ from settings.py
and will create aware
datetime objects instead of native
.
You should read https://docs.djangoproject.com/en/dev/topics/i18n/timezones/
这篇关于django中的运行时警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!