gpt4 book ai didi

django - 不是天真的日期时间(tzinfo 已经设置)

转载 作者:行者123 更新时间:2023-12-05 04:18:26 26 4
gpt4 key购买 nike

我在我的 Django 应用程序中使用 Django Celery,但我遇到了这个错误:

ValueError: Not naive datetime (tzinfo is already set) in djcelery.utils in make_aware

如何解决这个问题?

最佳答案

我认为这是 django-celery 在升级版本时出现的错误。但顺便说一下,将它放在 settings.py 所在的 init.py 中。

# Patch the djcelery/snapshot cause it's broken
import datetime
from django.utils.timezone import is_aware
import djcelery.snapshot
orig_maybe_make_aware = djcelery.snapshot.maybe_make_aware
def new_maybe_make_aware(value):
if isinstance(value, datetime.datetime) and is_aware(value):
return value
return orig_maybe_make_aware(value)
djcelery.snapshot.maybe_make_aware = new_maybe_make_aware

关于django - 不是天真的日期时间(tzinfo 已经设置),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14764884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com