问题
I am wondering if I can just define a variable like LONG_DATETIME_FORMAT = 'D d F Y H:i'
in my settings and use it in template like:
{{ my_date|date:"LONG_DATETIME_FORMAT" }}
? Can this be done without overwritting default date
filter? Or should I write custom filter?
回答1:
From the docs
The format passed can be one of the predefined ones
DATE_FORMAT
,DATETIME_FORMAT
,SHORT_DATE_FORMAT
orSHORT_DATETIME_FORMAT
, or a custom format that uses the format specifiers shown in the table above. Note that predefined formats may vary depending on the current locale.
So feel free to set any of them in the settings
DATETIME_FORMAT = 'D d F Y H:i'
{{ my_date|date:"DATETIME_FORMAT" }}
来源:https://stackoverflow.com/questions/35408993/django-extend-date-template-filter