django FORMAT_MODULE_PATH not working

若如初见. 提交于 2019-12-04 05:37:36

问题


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')


来源:https://stackoverflow.com/questions/21297299/django-format-module-path-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!