How to use FORMAT_MODULE_PATH

I am trying to make a change to the format of date time in a template. In DJ 5, it seems that USE_L10N is always true, and I am supposed to use the “FORMAT_MODULE_PATH” to specify where a formats.py file is that then defines some things like DATETIME_FORMAT.

This all makes sense conceptually, but it also doesn’t seem to work. I have this in my settings file:

LANGUAGE_CODE='en-us'
TIME_ZONE = 'America/New_York'
FORMAT_MODULE_PATH = [
    "student_tracker.formats",
    "student_track.formats",
]
USE_L10N=True
USE_I18N = True
USE_TZ = True
USE_THOUSAND_SEPARATOR = True

and then in my student_track app I have:

/formats/en_us/formats.py which contains this:

DATE_FORMAT = "M. d, Y"
TIME_FORMAT = "g:i a"

DATETIME_FORMAT = "M. d Y H:i a"
# DATETIME_FORMAT = f"{DATE_FORMAT} {TIME_FORMAT}"


DATE_INPUT_FORMATS = [
    '%m/%d/%Y', '%m/%d/%y', '%Y-%m-%d',  # '2006-10-25', '10/25/2006', '10/25/06'
    '%b %d %Y', '%b %d, %Y',  # 'Oct 25 2006', 'Oct 25, 2006'
    '%d %b %Y', '%d %b, %Y',  # '25 Oct 2006', '25 Oct, 2006'
    '%B %d %Y', '%B %d, %Y',  # 'October 25 2006', 'October 25, 2006'
    '%d %B %Y', '%d %B, %Y',  # '25 October 2006', '25 October, 2006'
]

But when I render my template which has this:

<td class="text-start">{{ record.actual_date|date:"DATETIME_FORMAT" }} </td>

I still get the default (and not what I want) DateTime format.

I don’t understand why it is so difficult to simply get a format for all date/times that I want.

No idea how to figure out what is wrong or debug what is being done and could use help.

Side note: When posting code or templates here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum to keep your code properly formatted. (I’ve taken the liberty of fixing your original post for this.)

Ah…I wasn’t sure how to do that…thanks for the tip!

I may have figured it out - but feels like it is a “bug”…not super experienced with this, so could use some help deciding if it is a bug or my lack of knowledge or both :slight_smile:

Here is what seems to work:
In my settings:

LANGUAGE_CODE='en-us'
TIME_ZONE = 'America/New_York'
FORMAT_MODULE_PATH = [
    "student_track.formats",
]
USE_L10N=True
USE_I18N = True
USE_TZ = True
USE_THOUSAND_SEPARATOR = True

then in my student_track app:
Previously I had this file:

/formats/en_us/formats.py

but this failed to load, so I changed it to this:

/formats/en_US/formats.py

(Note the Upper Case for the country)

In my formats.py i still have:

DATE_FORMAT = "M. d, Y"
TIME_FORMAT = "h:i a"

DATETIME_FORMAT = "M. d Y h:i a"
# DATETIME_FORMAT = f"{DATE_FORMAT} {TIME_FORMAT}"


DATE_INPUT_FORMATS = [
    '%m/%d/%Y', '%m/%d/%y', '%Y-%m-%d',  # '2006-10-25', '10/25/2006', '10/25/06'
    '%b %d %Y', '%b %d, %Y',  # 'Oct 25 2006', 'Oct 25, 2006'
    '%d %b %Y', '%d %b, %Y',  # '25 Oct 2006', '25 Oct, 2006'
    '%B %d %Y', '%B %d, %Y',  # 'October 25 2006', 'October 25, 2006'
    '%d %B %Y', '%d %B, %Y',  # '25 October 2006', '25 October, 2006'
]

Template I now have:

<td class="text-start" >{{ record.actual_date }} </td>

(Note the lack of the date filter)

and now it all works.