Django:获取SignUpForm没有属性clean_data的错误

时间:2016-01-08 05:12:23

标签: python django forms models

这是东西。我不确定哪个部分出了问题。请帮帮我! :)我是一个迷茫的ebit困惑哈哈哈

class SignUpForm(forms.ModelForm):
    fname = forms.CharField(max_length=256, label="", required=True, widget=forms.TextInput(attrs={'class': 'form-control','placeholder': 'First Name','required':True}))
    lname = forms.CharField(max_length=256, label="", required=True, widget=forms.TextInput(attrs={'class': 'form-control','placeholder': 'Last Name','required':True}))
    email = forms.EmailField(max_length=256, label="", required=True, widget=forms.EmailInput(attrs={'class': 'form-control','placeholder': 'Email','required':True}))
    emailConfirm = forms.EmailField(max_length=256, label="", required=True, widget=forms.EmailInput(attrs={'class': 'form-control','placeholder': 'Confirm email','required':True}))
    password = forms.CharField(max_length=256, label="", required=True, widget=forms.PasswordInput(attrs={'class': 'form-control','placeholder': 'Password','required':True}))
    datetime = forms.DateTimeInput()
    class Meta:
        model=SignUp
        fields=['fname','lname','email','password',]

    def clean_fname(self):
        name = self.clean_data.get('fname')
        if ' ' in name:
            raise forms.ValidationError("Please do not have a space in your name.")
        else:
            return name

2 个答案:

答案 0 :(得分:6)

那里没有属性clean_data或许cleaned_data会帮助你...

答案 1 :(得分:1)

clean_data在以前的django版本中使用,而不是使用cleaned_data 你的问题将得到解决