您可以clean()
在表单中添加方法以确保日期不是过去的日期。
import datetime
class MyForm(forms.Form):
date = forms.DateField(...)
def clean_date(self):
date = self.cleaned_data['date']
if date < datetime.date.today():
raise forms.ValidationError("The date cannot be in the past!")
return date
参见http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a- specific-field- attribute