一、先看报错:

django 在处理datetime类型的的报错
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py:1451: RuntimeWarning: DateTimeField Person.birthday received a naive datetime (2017-12-02 08:02:02.776941) while time zone support is active.

二、问题分析:

  1、默认情况下django中对时区的配置是UTC的、然而datetime中并没有明确指点时区、这样就冲突了。

三、解决方案1:

  使用django提供的timezone类

import django
import pytz
from django.utils import timezone
from datetime import datetime django.setup()
from polls.models import Person p=Person()
p.name='welson'
p.birthday=timezone.now()
p.save()

三、timezone和python内置的datetime的不同:

import django.timezone
from datetime import datetime datetime.now()
datetime.datetime(2017, 12, 2, 8, 37, 11, 354441) timezone.now()
datetime.datetime(2017, 12, 2, 8, 36, 49, 310501, tzinfo=<UTC>)

----

django -- while time zone support is active的更多相关文章

  1. Django时间时区问题(received a naive datetime while time zone support is active)

    在django1.4以后,存在两个概念 naive time 与 active time. 简单点讲,naive time就是不带时区的时间,Active time就是带时区的时间. 举例来说,使用d ...

  2. django中使用时间帅选报RuntimeWarning: DateTimeField Coupon.valid_begin_date received a naive datetime (2018-08-16 20:51:40.135425) while time zone support is active.

    今天在使用当前时间进行筛选数据时出现了RuntimeWarning: DateTimeField Coupon.valid_begin_date received a naive datetime ( ...

  3. Django报Warning错误 RuntimeWarning: DateTimeField Goods.create_at received a naive datetime (2019-07-31 23:05:58) while time zone support is active

    报错和UTC(世界标准时间)有关,在settings.py 文件中设置 USE_TZ = False 警告错误不再报

  4. 报错解决——DateTimeField *** received a naive datetime (***) while time zone support is active

    这是一个跟时区有关的问题,报错中说到datetime字段得到一个naive datetime,而不是支持time zone的active datetime由于Django的设置中米哦人USE_TZ设置 ...

  5. RuntimeWarning: DateTimeField AppToken.expire_date received a naive datetime (2019-05-16 16:54:01.144582) while time zone support is active. RuntimeWarning)

    数据库存储当前时间操作: datetime.datetime.now() 更改为: from django.utils import timezone timezone.now()

  6. 【转载】在使用JDBC连接MySql时报错:You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support

    在使用JDBC连接MySql时报错:You must configure either the server or JDBC driver (via the serverTimezone config ...

  7. Python & Django 学习笔记

    最近在学校Python和Django.在学习中遇到了种种的问题,对于一个新手来说,下面的问题可能都会遇到.希望能帮助到那些和我一样的人!!0.python-dev安装(ubuntu)  apt-get ...

  8. Django models通过DateTimeField保存到MySQL的时间的时区问题

    最近开始使用Django开发一些系统,在models.py中设置一些数据库表结构并给日期时间字段赋初值,不过在使用的过程中,遇到一点问题.问题是,我本来服务器使用的市区是“Asia/Shanghai” ...

  9. Django入门开发之数据模型01

    1. Django安装 [root@HappyLau ~]# pip install django==1.8.2 2. 创建项目 [root@HappyLau html]# django-admin ...

随机推荐

  1. IDEA引入外部jar包的方法

    在做发短信的功能(阿里大于)的时候,我只是吧jar包拷贝到了项目的external library. 拷贝进来之后我用junit写了test方法,可以完美发送短信到手机,但是我这是个web项目,然后我 ...

  2. httpclient Accept-Encoding 乱码

    解决方法 HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { if (httpEntity.getC ...

  3. 三分钟彻底禁用、隐藏Android设备底部虚拟按钮(亲测有效)

       转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7613970.html Android设备屏幕底部一般都有虚拟导航栏,上面有 back.home等按钮. ...

  4. V-rep学习笔记:Reflexxes Motion Library 1

    V-REP中集成了在线运动轨迹生成库Reflexxes Motion Library Type IV,目前Reflexxes公司已经被谷歌收购.(The Reflexxes Motion Librar ...

  5. python模块之HTMLParser解析出URL链接

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser解析出URL链接 #http://www.cnblogs.com/mf ...

  6. Openwrt中用iftop查看网络流量情况

    iftop可以查看指定网卡上的流量情况, 命令说明 iftop: display bandwidth usage on an interface by host Synopsis: iftop -h ...

  7. 【转】【MySQL】MySQL的双机互信实战

    [转]https://www.cnblogs.com/mchina/archive/2013/03/15/2956017.html MySQL双机实战原理:利用ssh传输文件,通过公.私钥的共享,实现 ...

  8. 回到顶部bug

    参考自一博客(https://www.cnblogs.com/abao0/p/6642288.html)内有慕课网教程(后发现有bug, 弃置不用了) 以下有问题, 当滚动条处于顶部时, 刷新页面, ...

  9. java 获取当前日期和特殊日期格式转换

     1.获取当前日期: package com.infomorrow.dao; import java.sql.Timestamp; import java.util.Calendar; import ...

  10. iOS中消息传递方式

    iOS中消息传递方式 在iOS中有很多种消息传递方式,这里先简单介绍一下各种消息传递方式. 1.通知:在iOS中由通知中心进行消息接收和消息广播,是一种一对多的消息传递方式. NSNotificati ...