当前位置 : 主页 > 网络编程 > 其它编程 >

Django的DateTimeField警告

来源:互联网 收集:自由互联 发布时间:2023-07-02
问题lib\site-packages\django\db\models\fields\__init__.py:1418:RuntimeWarning:DateTimeField 问题 lib\site-packages\django\db\models\fields\__init__.py:1418: RuntimeWarning: DateTimeField DispatchingPlan.start_time received a naive dateti
问题lib\site-packages\django\db\models\fields\__init__.py:1418:RuntimeWarning:DateTimeField

问题

lib\site-packages\django\db\models\fields\__init__.py:1418: RuntimeWarning: DateTimeField DispatchingPlan.start_time received a naive datetime (2022-03-01 16:00:00) while time zone support is active.warnings.warn("DateTimeField %s received a naive datetime (%s)"lib\site-packages\django\db\models\fields\__init__.py:1418: RuntimeWarning: DateTimeField DispatchingPlan.start_time received a naive datetime (2022-03-02 16:00:00) while time zone support is active.warnings.warn("DateTimeField %s received a naive datetime (%s)"

是一个跟时区有关的问题需要的是 active time带时区的utc时间但是收到的是 naive time不带时区的utc时间。

解决办法

  • 推荐如果项目需要按时区显示获取时间的时候加上时区参数

    from django.utils import timezonedatetime.datetime(2013, 11, 20, 20, 8, 7, 127325,tzinfotimezone.utc)

  • 如果项目不需要按时区显示就把 settings.py

    LANGUAGE_CODE zh-hansTIME_ZONE Asia/ShanghaiUSE_I18N TrueUSE_L10N True# 这个改为 FalseUSE_TZ False

  • 参考

    https://stackoverflow.com/questions/18622007/runtimewarning-datetimefield-received-a-naive-datetime

    https://www.cnblogs.com/zhuminghui/p/9196801.html

    上一篇:C#_UnitTesting一(xUnit)
    下一篇:没有了
    网友评论