There is an official way to do this now since the closing of Django ticket 6483 & release of Django 1.2.
If you have USE_L10N
set to False
, what you should do is specify the DATE_INPUT_FORMATS
and DATETIME_INPUT_FORMATS
in your settings.py
. Here are the settings I use for this, based on converting the defaults:
#dd/mm/yyyy and dd/mm/yy date & datetime input field settings
DATE_INPUT_FORMATS = ('%d-%m-%Y', '%d/%m/%Y', '%d/%m/%y', '%d %b %Y',
'%d %b, %Y', '%d %b %Y', '%d %b, %Y', '%d %B, %Y',
'%d %B %Y')
DATETIME_INPUT_FORMATS = ('%d/%m/%Y %H:%M:%S', '%d/%m/%Y %H:%M', '%d/%m/%Y',
'%d/%m/%y %H:%M:%S', '%d/%m/%y %H:%M', '%d/%m/%y',
'%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', '%Y-%m-%d')
If you have USE_L10N
set to True
, then you will need to use the FORMAT_MODULE_PATH
instead.
For example, my LANGUAGE_CODE
is set to en-au
, my site is called golf
, and my FORMAT_MODULE_PATH
is set to golf.formats
, so my directory structure looks like this:
golf/
settings.py
...
formats/
__init__.py
en/
__init__.py
formats.py
and the DATE_INPUT_FORMATS
and DATETIME_INPUT_FORMATS
settings are in formats.py
instead of settings.py
.