#35978: Django Rest Framework - How do i actually use a custom date format?
-------------------------------------+-------------------------------------
Reporter: Federico_Bucciero | Type:
| Uncategorized
Status: new | Component:
| Documentation
Version: 5.1 | Severity: Normal
Keywords: DATE_INPUT_FORMAT | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hi there,
using drf, i developed a simple api for an internal project.
I got asked to change the format of the date field from the ISO format
"%Y-%m-%d" to the format '%d.%m.%Y'.
I read and re-read the documentation, jumped from forum and discussion,
but i can't find a working solution.
The project structure is:
project/
api/
__init__.py
formats/
__init__.py
it/
__init__.py
formats.py
migrations/
admin.py
apps.py
...
backend/
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
in project/backend/settings.py i have set
LANGUAGE_CODE = 'it'
FORMAT_MODULE_PATH = ['api.formats',]
and in project/api/formats/it/formats.py i have set
DATE_INPUT_FORMATS = [
'%d/%m/%y',
'%d/%m/%Y',
'%d.%m.%Y',
'%d.%m.%y',
'%Y-%m-%d',
# etc
]
but still doesn't work, and fails my request, asking for a date in format
'%Y-%m-%d'
The documentation doesn't help really much undestanding how to properly
customize the format, as this "The locale-dictated format has higher
precedence and will be applied instead." tries to imply that customization
is impossible.
Django version: 5.1.4
djangorestframework version: 3.15.2
--
Ticket URL: <
https://code.djangoproject.com/ticket/35978>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.