RuntimeWarning: DateTimeField User.date_joined received a naive datetime (2020-08-01 00:00:00) while time zone support is active. warnings.warn("DateTimeField %s.%s received a naive datetime "问题

 

django项目中比较时间参数操作数据库是,产生warning:

RuntimeWarning: DateTimeField User.date_joined received a naive datetime (2020-08-01 00:00:00) while time zone support is active.   warnings.warn("DateTimeField %s.%s received a naive datetime "

综合网络,发现有两种解决方式:

第一种:

修改settings.py文件中的USE_TZ值为False

USE_TZ = False

第二种:

不要使用datatime模块,使用django中自带是时间模块:

from django.utils import timezone

data_time = timezone.now()

 

posted @ 2020-08-07 14:43  sewen  Views(2796)  Comments(0Edit  收藏  举报