[英]How to convert datetime to string in python in django
I have a datetime object at my model. 我的模型上有一个日期时间对象。 I am sending it to the view, but in html i don't know what to write in order to format it. 我发送它到视图,但在HTML中我不知道写什么来格式化它。
I am trying 我在尝试
{{ item.date.strftime("%Y-%m-%d")|escape }}
but I get 但我明白了
TemplateSyntaxError: Could not parse some characters: item.date.strftime|("%Y-%m-%d")||escape
when I am just using 当我刚刚使用时
{{ item.date|escape }}
it's working, but now with the format I want. 它正在工作,但现在我想要的格式。
Any suggestions? 有什么建议么?
请尝试使用内置的Django 日期格式过滤器 :
{{ item.date|date:"Y M d" }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.