在页168上,有两段代码:
def clean_password2(self):
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError("You must type the same password each time")
return self.cleaned_data['password2']
def clean(self):
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError("You must type the same password each time")
return self.cleaned_data
在第二种情况下,代码检查'password1'和'password2'是否具有任何值。在第一种情况下,没有这样的检查。为什么?