Django, configuration data format 'd / m / Y' [duplicate]

1

I can not change the Django configuration so the date format is set to 'd / m / Y'. In the validation of the form, if you inform 22/12/1980, the form is invalid. By informing 12/22/1980 the date field is valid and I can save the record.

I've tried changing the following settings:

settings.py

LANGUAGE_CODE = 'pt-br'
USE_L10N = False

In the class, the attribute is defined as:

data_nascimento = models.DateField(null=False)

Is there any further configuration so that I can change the date format from 'm / d / Y' to 'd / m / Y'?

    
asked by anonymous 01.05.2017 / 14:47

1 answer

2

According to Django's settings , there is the DATE_INPUT_FORMATS :

  

The list of formats that will be accepted when inputting date on a date field.

That is, the list of formats that will be accepted for dates of entry into date type fields. By default, the property has the following value:

[
    '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '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'
]

You can change it as you wish, but if you just want a valid format, just do:

DATE_INPUT_FORMATS = ['%d/%m/%Y']

The above changes must be made to the settings.py of the project.

    
01.05.2017 / 16:26