Gijsriet
Gijsriet

Reputation: 163

'Date does not conform to the required format' after changing language in Django app

The specified value "06-03-2019" does not conform to the required format, "yyyy-MM-dd".

I use Django internationalisation in a webapplication and for some reason suddenly I get this error in the developer tools on a form date input after changing the language to Dutch. On English everything works fine, the error is not shown and date is saved correctly. I use he standard django forms dateInput.

I searched the webs for hours, before turning to your help. Any suggestions would be greatly appreciated!

Thanks.

Upvotes: 0

Views: 1038

Answers (2)

Gijsriet
Gijsriet

Reputation: 163

Actually, what solved the issue was setting it manually the other way around by adding format=('%Y-%m-%d').

        for field in date_fields:
        self.fields[field].widget = forms.DateInput(
            format=('%Y-%m-%d'),
            attrs={
                'type': 'date',
                'class': 'form-control',
                'max': now.strftime('%Y-%m-%d'),
                'data-msg-min': _("Kies een datum op of na {0}"),
                'data-msg-max': _("Kies een datum die niet in de toekomst ligt")
            },
        )

Upvotes: 1

p14z
p14z

Reputation: 1810

The problem is probably caused by the Localization, you can disable it on your form like this:

class ExampleForm(forms.Form):
   date_field = forms.DateField(localize=False)

I usually just disable localization globally in the settings:

USE_L10N = False

Upvotes: 0

Related Questions