How to convert datetime to string in python in django

I have a datetime object in my model. I send it to the view, but in html I do not know what to write to format it.

I'm trying to

{{ 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 just use

 {{ item.date|escape }} 

It works, but now with the format I want.

Any suggestions?

+4
source share
1 answer

Try using the built-in Django date format format :

 {{ item.date|date:"YM d" }} 
+11
source

All Articles