首页 > 其他 > 详细

DateTimeField *** received a naive datetime (***) while time zone support is active

时间:2020-06-22 21:47:59      阅读:70      评论:0      收藏:0      [点我收藏+]

django报错:

/usr/local/lib/python2.7/dist-packages/Django-1.8.2-py2.7.egg/django/db/models/fields/init.py:1474: RuntimeWarning: DateTimeField Org.updatedAt received a naive datetime (2017-06-16 04:51:17) while time zone support is active.
RuntimeWarning

解决方法:

时区问题,datetime.now()生成的不带时区的utc时间称为native time
使用django.utils.timezone.now()输出的是带时区的utc时间,称为active time
懒得一个个改,so:

# from datetime import datetime # 注释的
from django.utils import timezone as datetime # 添加的

参考文献:
1、https://blog.csdn.net/heybob/article/details/77319867 2019.6.27
2、http://www.zhixing123.cn/php/django-datetimefield-received-a-naive-da.html 2019.6.27

3、https://stackoverflow.com/questions/22028004/django-datetimefield-received-a-naive-datetime

DateTimeField *** received a naive datetime (***) while time zone support is active

原文:https://www.cnblogs.com/catgatp/p/13179120.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!