gpt4 book ai didi

python - 如何在 django 的 python 中将日期时间转换为字符串

转载 作者:太空狗 更新时间:2023-10-30 01:56:17 25 4
gpt4 key购买 nike

我的模型中有一个日期时间对象。我将它发送到 View ,但在 html 中我不知道要写什么来格式化它。

我在努力

{{ item.date.strftime("%Y-%m-%d")|escape }}

但是我明白了

TemplateSyntaxError: Could not parse some characters: item.date.strftime|("%Y-%m-%d")||escape

刚用的时候

{{ item.date|escape }}

它正在工作,但现在是我想要的格式。

有什么建议吗?

最佳答案

尝试使用内置的 Django date format filter相反:

{{ item.date|date:"Y M d" }}

关于python - 如何在 django 的 python 中将日期时间转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/794995/

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