Tuesday, January 29, 2013

Re: Help, getting keyerrors

I think I have it.
Changed to cleaned_data.get('password')

Thank you


On Tuesday, January 29, 2013 2:58:45 PM UTC-5, frocco wrote:
Thanks,
getting error now that I changed it.

def clean(self):
        cleaned_data = super(RegistrationForm, self).clean()
        password = cleaned_data['password']
        password1 = cleaned_data['password1']
        if password and password1 and password == password1:
            pass
        else:
            raise forms.ValidationError('The passwords did not match, Please try again.')
        return cleaned_data


RegistrationForm' object has no attribute 'password

On Tuesday, January 29, 2013 2:47:11 PM UTC-5, Nikolas Stevenson-Molnar wrote:
Your clean() method shouldn't use self.cleaned_data, it should call
super(RegistrationForm, self).clean(). E.g:

def clean(self):
    cleaned_data = super(RegistrationForm, self).clean()
    password = cleaned_data['password']
    ...
    return cleaned_data

https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

_Nik


On 1/29/2013 11:42 AM, frocco wrote:
> Hello,
> On my registration form, if I enter no data and just press enter, i
> get a key error.
> Can someone tell me what I am doing wrong?
> Thanks
>
> forms.py
> from django import forms
> from django.contrib.auth.models import User
> from django.forms import ModelForm
> from customer.models import Customer
>
> class RegistrationForm(forms.Form):
>     username = forms.CharField(label=u'User Name')
>     firstname = forms.CharField(label=u'First Name')
>     lastname = forms.CharField(label=u'Last Name')
>     email = forms.EmailField(label=u'Email Address')
>     company = forms.CharField(label=u'Company')
>     phone = forms.CharField(label=u'Phone')
>     password =
> forms.CharField(label=u'Password',widget=forms.PasswordInput(render_value=False),required=True)
>     password1 = forms.CharField(label=u'Verify
> Password',widget=forms.PasswordInput(render_value=False),required=True)
>
>     def clean_username(self):
>         username = self.cleaned_data['username']
>         try:
>             User.objects.get(username=username)
>         except User.DoesNotExist:
>             return self.cleaned_data['username']
>         raise forms.ValidationError('That username is already taken,
> please select another.')
>
>     def clean(self):
>         password = self.clean_password()
>         password1 = self.cleaned_data['password1']
>         if password and password1 and password == password1:
>             return self.cleaned_data
>         else:
>             raise forms.ValidationError('The passwords did not match,
> Please try again.')
>
>     def clean_company(self):
>         return self.cleaned_data['company']
>
>     def clean_phone(self):
>         return self.cleaned_data['phone']
>
>     def clean_email(self):
>         return self.cleaned_data['email']
>
>     def clean_firstname(self):
>         return self.cleaned_data['firstname']
>
>     def clean_lastname(self):
>         return self.cleaned_data['lastname']
>
>     def clean_password(self):
>         if self.password and self.cleaned_data['password']:
>             return self.cleaned_data['password']
>         else:
>             raise forms.ValidationError("Enter a password.")
>
>
>     def clean_password1(self):
>         if not self.cleaned_data['password1']:
>             raise forms.ValidationError("Enter your password (again)")
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment