class Register(forms.Form):
passwd = forms.CharField(max_length=20,label='密码',widget=forms.PasswordInput)
repasswd = forms.CharField(max_length=20,label='重复密码',widget=forms.PasswordInput)
def clean_passwd(self):
passwd = self.cleaned_data['passwd']
repasswd = self.cleaned_data['repasswd'] #here is error
if passwd != repasswd:
raise forms.ValidationError('两次密码不一致')
return passwd
So,problems is i want to check passwd and repasswd same,How to solve?
def clean(self):
cleaned_data = super(Register,self).clean()
passwd = cleaned_data.get('passwd')
repasswd = cleaned_data.get('repasswd')
if(passwd != repasswd):
self.add_error('repasswd',u'两次密码不一致')
another is clean_passwd():
def clean_passwd(self):
passwd = self.cleaned_data.get('passwd')
repasswd = self.cleaned_data.get('repasswd')
if passwd != repasswd:
raise forms.ValidationError('两次密码不一致')
return passwd
change my code
repasswd = self.cleaned_data['repasswd']
to
repasswd = self.cleaned_data.get('repasswd')
def clean(self):
cleaned_data = super(Register,self).clean()
passwd = cleaned_data.get('passwd')
repasswd = cleaned_data.get('repasswd')
if(passwd != repasswd):
self.add_error('repasswd',u'两次密码不一致')
And last,I want konw how to send a web pag (can auto jumps Specific location) to others,such as you url在 2017年7月18日星期二 UTC+8下午5:57:35,Jani Tiainen写道:
"https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L64"