Django date filter: how come the format used is different from the one in datetime library ???

Posted by Sébastien Piquemal on Stack Overflow See other posts from Stack Overflow or by Sébastien Piquemal
Published on 2010-06-10T13:10:45Z Indexed on 2010/06/10 13:12 UTC
Read the original article Hit count: 365

Filed under:
|
|
|
|

Hello ! For formatting a date using date filter you must use the following format :

{{ my_date|date:"Y-m-d" }}

If you use strftime from the standard datetime, you have to use the following :

my_date.strftime("%Y-%m-%d")

So my question is ... isn't it ugly (I guess it is because of the % that is used also for tags, and therefore is escaped or something) ?

But that's not the main question ... I would like to use the same DATE_FORMAT parametrized in settings.py all over the project, but it therefore seems that I cannot ! Is there a work around (for example a filter that removes the % after the date has been formatted like {{ my_date|date|dream_filter }}, because if I just use DATE_FORMAT = "%Y-%m-%d" I got something like %2001-%6-%12)?

© Stack Overflow or respective owner

Related posts about python

Related posts about django