我的模型中有一个日期时间对象。 我将它发送到 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/