양식 유효성 검사를 시도하고 있습니다 (이전에는 작동 했었습니다). 어떤 이유로 인해 form.is_valid()가 호출 될 때 clean_username (self)와 같은 다양한 클리닝 함수를 호출 할 수없는 것처럼 보입니다. 나는 거의 충분한 검사가없는 것을 알고Django 폼이 정상적으로 호출되지 않습니다. <fieldname>
아직 (그들은 당신이 ;-) 볼 공사중),하지만 여기 내 클래스입니다 :
class LoginForm(forms.Form):
username = forms.CharField(max_length=30)
password = forms.CharField(max_length=30,widget=forms.PasswordInput)
def clean_password(self):
print "Cleaning password"
password = self.cleaned_data['password']
if password == u"":
raise forms.ValidationError("Password is blank.")
return password
def clean_username(self):
username = self.cleaned_data['username']
if len(username) < 4:
raise forms.ValidationError("Username is fewer than four charecters.")
return username
class RegistrationForm(LoginForm):
confirm_password = forms.CharField(widget=forms.PasswordInput, max_length=30)
email = forms.EmailField()
def clean_confirm_password(self):
print "Cleaning confirm password"
clean_confirm_password = self.cleaned_data['confirm_password']
if clean_confirm_password == u"":
raise forms.ValidationError("Confirming password is blank.")
return clean_confirm_password
def clean(self):
print "Running clean on a registration form"
print self.cleaned_data.items()
password = self.cleaned_data['password']
confirm = self.cleaned_data['confirm_password']
if password != confirm:
raise forms.ValidationError('Passwords do not match.')
return self.cleaned_data
감사합니다!
1. 사람들이 사용 가능한 소스 코드를 들여다 보지 않을 것인가는 나를 깜짝 놀라게한다. – cethegeek
그것은 무서울 수 있습니다. 나는 우연히 중요한 것을 변화시키고 저장하는 것을 두려워합니다. 불합리한 것, 나는 모든 것이 쉽게 대체 될 수있을 때를 안다. ;-) – SapphireSun