class RegisterForm(forms.Form):
username = forms.CharField(max_length=16, label="Username", required=False)
password = forms.CharField(max_length=100,widget=forms.PasswordInput, required=False)
password2 = forms.CharField(max_length=100,widget=forms.PasswordInput, label="Password Again", required=False)
fullname = forms.CharField(max_length = 100, required=False)
email = forms.EmailField(max_length=100, required=False)
def clean_fullname(self):
if len(self.cleaned_data['fullname']) < 4:
raise forms.ValidationError("Enter your full name.")
def clean_email(self):
if self.cleaned_data['email'].find("@") <= 0:
raise forms.ValidationError("Enter a valid email address.")
def clean_username(self):
if not self.cleaned_data['username']:
raise forms.ValidationError("Enter a username.")
try:
u = User.objects.get(username = self.cleaned_data['username'])
if u:
raise forms.ValidationError("Username is taken.")
except:
pass
def clean_password(self):
if not self.cleaned_data['password']:
raise forms.ValidationError("Enter a password.")
def clean_password2(self):
if not self.cleaned_data['password2']:
raise forms.ValidationError("Enter your password (again)")
def clean(self):
cleaned_data = self.cleaned_data
password = cleaned_data['password'] <<< There is a key error here anytime I submit a form.
password2 = cleaned_data['password2']
if password and password2:
if password != password2:
raise forms.ValidationError("Your passwords do not match.")
return cleaned_data
Es gibt einen Schlüsselfehler auf S. assword = cleaned_data['password']
Warum gibt es einen Schlüsselfehler in dieser Zeile meines Django-Formularcodes?
Ja, mein cleaned_data ist leer. Weißt du, warum? – TIMEX
Nein, ich weiß nicht warum. Wenn ich Zugriff auf Ihr System hätte und wüsste, wo ich die Django-Dokumente finden könnte, würde ich prüfen, ob alle von mir gelieferten Methoden den Anforderungen entsprechen. Hast du das gemacht? –