- 这个文件在E:\django5env\Lib\site-packages\django\contrib\auth\forms.py ,其中写了好几个关于form的,可以参考其验证、错误信息等方法
class PasswordChangeForm(SetPasswordForm):"""A form that lets a user change their password by entering their oldpassword."""error_messages = {**SetPasswordForm.error_messages,"password_incorrect": _("Your old password was entered incorrectly. Please enter it again."),}old_password = forms.CharField(label=_("Old password"),strip=False,widget=forms.PasswordInput(attrs={"autocomplete": "current-password", "autofocus": True}),)field_order = ["old_password", "new_password1", "new_password2"]def clean_old_password(self):"""Validate that the old_password field is correct."""old_password = self.cleaned_data["old_password"]if not self.user.check_password(old_password):raise ValidationError(self.error_messages["password_incorrect"],code="password_incorrect",)return old_password