hi,
i’ve just update my Django version to 5 but i notice that datetime not taking short datetime format
from settings SHORT_DATETIME_FORMAT i’ve put it mak it to another format
is this a bug or the setting has changed
this is my settings
SHORT_DATETIME_FORMAT = ‘Y-m-d H:i:s’
but it shows in HTML like this May 2, 2024, 3:56 p.m.
and thank you
How are you rendering that field in your template?
like this {{ item.created_on }} for example
not only this one all fields with datetime
See the docs for the date
filter to identify a format to use when rendering a date or datetime field.
but I wasn’t using it and the format was rendering like I put it in settings is this changed in the new Django version??
just when I’ve used this format works fine in settings
DATETIME_FORMAT = ‘Y-m-d H:i:s’
from django.conf.locale.en import formats
formats.DATETIME_FORMAT = DATETIME_FORMAT
can I do it without using this
DATETIME_FORMAT
is not SHORT_DATETIME_FORMAT
From the docs for DATETIME_FORMAT:
The default formatting to use for displaying datetime fields in any part of the system.
i know but why it not work as intended unless I’m do this change
DATETIME_FORMAT = ‘Y-m-d H:i:s’
from django.conf.locale.en import formats
formats.DATETIME_FORMAT = DATETIME_FORMAT
I’m sorry, I’m not following you here.
What doesn’t work? What is intended?
in django 4.2 and older when i use in template any datetime from model the format work as this
DATETIME_FORMAT = ‘Y-m-d H:i:s’ format
but in django 5 when I use datetime field in template the format is the default one
this
Default: 'N j, Y'
(e.g. Feb. 4, 2003
)
There was a change in the docs between 4.2 and 5.0 that may explain your situation.
In 4.2, DATETIME_FORMAT:
Note that if
USE_L10N
is set toTrue
, then the locale-dictated format has higher precedence and will be applied instead.
Since the USE_L10N
setting was removed in 5.0, the docs now read:
Note that the locale-dictated format has higher precedence and will be applied instead.
(In other words, locale-defined formats always take precedence.)
This means that you either need to change the locale format, or specifically use this format in the template.
thank you that makes sense now