问题
In forms.py:
class DobForm(forms.ModelForm)
dob = forms.DateField(widget=forms.TextInput(attrs={'class':'datepicker'}),required=True,input_formats=['%d/%m/%Y',])
class Meta:
model = Dob
In my html:
$(function() {$(".datepicker").datepicker({ maxDate: '0',dateFormat: 'dd-mm-yy' })});</script>
Its thorwing error in the form: Enter a valid date
回答1:
You need to make the formats the same for both django and jquery.
Try this for the DateField (django):
...,input_formats=['%d-%m-%Y',])
and in the html use:
...,dateFormat: 'dd-mm-yyyy' })});</script>
I hope this works.
来源:https://stackoverflow.com/questions/37451479/how-to-change-django-date-format-to-dd-mm-yy