How can I set a DateField format in django from the model?

后端 未结 3 1011
一向
一向 2020-12-13 14:20

I am creating a django application and I have the next problem: this error is shown when I want to set a date:

ValidationError [u\"\'12/06/2012\' value has a         


        
3条回答
  •  抹茶落季
    2020-12-13 14:58

    You could also use the LANGUAGE_CODE to get the correct date formate for the local. LANGUAGE_CODE ='en-GB' Then have DATE_INPUT_FORMATS = ['%d-%m-%Y', '%Y-%m-%d'] in the settings.py which can be called when needed at anytime.

    date_birth = forms.DateField(label='Date of birth', widget=forms.SelectDateWidget(years=YEAR_CHOICES, input_formats= DATE_INPUT_FORMATS))

提交回复
热议问题