Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert datetime to string in python in django

Tags:

python

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.

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?

like image 465
Stavros Avatar asked Dec 22 '22 11:12

Stavros


1 Answers

Try using the built-in Django date format filter instead:

{{ item.date|date:"Y M d" }}
like image 185
Jarret Hardie Avatar answered Jan 14 '23 07:01

Jarret Hardie