django FORMAT_MODULE_PATH not working

2019-03-03 20:54发布

问题:

Base on this question and documentation

I have created a format structure

  mysite
    |
    mysite
    ├── en_NZ # I also tried en_NZ.UTF-8
    │   ├── formats.py
    │   ├── formats.pyc
    │   ├── __init__.py
    │   └── __init__.pyc
    ├── __init__.py
    └── __init__.pyc

which formats.py looks like this:

DATE_FORMAT = '%d/%m/%Y'

and in settings.py:

FORMAT_MODULE_PATH = 'mysite.formats'

my locale information on my server is:

$locale
LANG=en_NZ.UTF-8
LANGUAGE=
LC_CTYPE="en_NZ.UTF-8"
LC_NUMERIC="en_NZ.UTF-8"
LC_TIME="en_NZ.UTF-8"
LC_COLLATE="en_NZ.UTF-8"
LC_MONETARY="en_NZ.UTF-8"
LC_MESSAGES="en_NZ.UTF-8"
LC_PAPER="en_NZ.UTF-8"
LC_NAME="en_NZ.UTF-8"
LC_ADDRESS="en_NZ.UTF-8"
LC_TELEPHONE="en_NZ.UTF-8"
LC_MEASUREMENT="en_NZ.UTF-8"
LC_IDENTIFICATION="en_NZ.UTF-8"
LC_ALL=

but the date string in admin still in YYYY-MM-DD format, any ideas?

回答1:

It's actually consulting the formats, I just needed to add 2 more settings to the formats.py

DATE_FORMAT = '%d/%m/%Y'
DATE_INPUT_FORMATS = ('%d/%m/%Y', '%Y-%m-%d')
DATETIME_INPUT_FORMATS = ('%d/%m/%Y %H:%M:%S', '%Y-%m-%d %H:%M:%S')