django -- while time zone support is active
一、先看报错:
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的更多相关文章
- Django时间时区问题(received a naive datetime while time zone support is active)
在django1.4以后,存在两个概念 naive time 与 active time. 简单点讲,naive time就是不带时区的时间,Active time就是带时区的时间. 举例来说,使用d ...
- 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 ( ...
- 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 警告错误不再报
- 报错解决——DateTimeField *** received a naive datetime (***) while time zone support is active
这是一个跟时区有关的问题,报错中说到datetime字段得到一个naive datetime,而不是支持time zone的active datetime由于Django的设置中米哦人USE_TZ设置 ...
- 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()
- 【转载】在使用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 ...
- Python & Django 学习笔记
最近在学校Python和Django.在学习中遇到了种种的问题,对于一个新手来说,下面的问题可能都会遇到.希望能帮助到那些和我一样的人!!0.python-dev安装(ubuntu) apt-get ...
- Django models通过DateTimeField保存到MySQL的时间的时区问题
最近开始使用Django开发一些系统,在models.py中设置一些数据库表结构并给日期时间字段赋初值,不过在使用的过程中,遇到一点问题.问题是,我本来服务器使用的市区是“Asia/Shanghai” ...
- Django入门开发之数据模型01
1. Django安装 [root@HappyLau ~]# pip install django==1.8.2 2. 创建项目 [root@HappyLau html]# django-admin ...
随机推荐
- Javascript中怎样获取统一管理的Java提示语
项目开发中,各个页面.各个业务操作都会使用提示语.面对这么多message,更好的方式是统一管理这些消息. 这样在做国际化的时候进行统一处理也变的方便. 推荐方案使用数据库来管理全部提示语,在项目启动 ...
- VB.NET版+三层实现登陆
三层已经学了一些时间了,開始认为自己能够用C#敲代码了,就用C#写了一个实现登陆的,真正再用在机房中.还是认为非常吃力的,所以.决定用vb.net敲了.以下是我用vb.net实现的登陆.能够给大家做一 ...
- 微信小程序图片上传并展示
1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...
- Android 使用DDMS查看内存使用情况
- Maven的坐标与资源库
在Maven世界中,每个工程都有它唯一的 组织名.模块名.版本 ,这三个就是maven项目的坐标,一个maven工程可以打包成jar.war.pom等形式,但是它们都是拥有上述三个坐标的.我们在项目过 ...
- 【Linux】处理数据文件
当存在大量数据的时候,通常很难处理这些信息及提取有用信息.Linux提供了一系列的命令行工具来处理这些数据. 1.排序数据 Linux:/usr/local/sbin # cat file2 1 0. ...
- 将excel表导入到mysql中
//导入excel表 方法一: )打开Excel另存为CSV文件 )将文件编码转化为utf8,用NotePad++打开csv文件,选择格式—转为utf8编码格式—保存 )在MySQL建表,字段的顺序要 ...
- Centos7 安装 docker-ce
本文参考官网地址:https://docs.docker.com/install/linux/docker-ce/centos/#os-requirements 1.卸载旧版本的docker $ su ...
- logstash写日志elaticsearch不响应
在大量的解析日志并写入elasticsearch,在后端节点数据数量及磁盘性能等影响下,es不响应 问题描述: [--12T17::,][WARN ][logstash.outputs.elastic ...
- 图片异步加载之EGOImageLoading
下载地址 http://pan.baidu.com/share/link?shareid=2690186349&uk=923776187 引入目录 简单实用 http://blog.csdn ...