WARNINGS.WARN(“ DateTimeField%s)收到了幼稚的DateTime(%S)”
我使用django简单历史来获取模型的历史 然后,我按日期搜索历史记录结果,但下面会出现错误。如何格式化日期?
RuntimeWarning: DateTimeField HistoricalIssue.history_date received a naive datetime (2022-04-13 10:34:32) while time zone support is active.
warnings.warn("DateTimeField %s received a naive datetime (%s)"
def SearchByDate(request):
date_search = request.POST['date-search']
if date_search:
admin_hist_search_results = Issue.history.filter(history_date=date_search)
I use django simple-history to get history on my models
I then search the history results by date but I get the error below. How can I format the date?
RuntimeWarning: DateTimeField HistoricalIssue.history_date received a naive datetime (2022-04-13 10:34:32) while time zone support is active.
warnings.warn("DateTimeField %s received a naive datetime (%s)"
def SearchByDate(request):
date_search = request.POST['date-search']
if date_search:
admin_hist_search_results = Issue.history.filter(history_date=date_search)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请记住,这不是错误,而是“只”警告。它提到传入的时间戳(您将其存储在变量
date_search
中)没有时区信息,而您将其与时间戳字段进行比较(history_date_date
on Model问题
)确实具有时区信息。这可能会导致问题。如果您知道来自请求的时区,则可以将该信息添加到时间戳,例如:
First, keep in mind that this is not an error, but "only" a warning. It mentions that the incoming timestamp (which you store in variable
date_search
) does not have timezone information, while you compare it with a timestamp field (history_date
on modelIssue
) that does have timezone information. This could potentially lead to issues.If you know the timezone coming in from the request, you can add that information to the timestamp, for example: