开发者

Simple Django template question

开发者 https://www.devze.com 2023-03-11 09:15 出处:网络
I have a template variable: {{article.pub_date}} that outputs this: May 25, 开发者_如何学Python2011, 7:52 p.m.

I have a template variable:

   {{article.pub_date}}

that outputs this:

   May 25, 开发者_如何学Python2011, 7:52 p.m.

How can I get just the date without the time:

May 25, 2011

without the:

, 7:52 p.m.

I only have access to the template tags/variables not the python code.


{{ article.pub_date|date:"DATE_FORMAT" }}

https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date


{{article.pub_date|date:"F j, Y"}}

Django uses the same formatting as PHP date objects.


Also you can set a default format if you want a format used all over the site

https://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#date-format

0

精彩评论

暂无评论...
验证码 换一张
取 消