Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Seeing 'SignupForm' object has no attribute 'instance' on Django Form

I am on Django 4.0.x and running over and over into the same issue when validating a form.

Always seeing: ‘SignupForm’ object has no attribute ‘instance’

Here is my view:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def signup(request):

if request.method == "POST":
    signup_form = SignupForm(request.POST)
    if signup_form.is_valid():
        email = signup_form.cleaned_data['email']

else:
    signup_form = SignupForm()

return render(request, 'signup.html', {'signup_form': signup_form})

and the according forms.py:

class SignupForm(forms.Form):
email = forms.EmailField(label=_("E-Mail Address"), validators=[EmailValidator()])
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput())
password_confirm = forms.CharField(label=_("Confirm Password"), widget=forms.PasswordInput())

def clean_email(self):
    data = self.cleaned_data['email']
    if forms.ValidationError:
        self.add_error('email', forms.ValidationError)
    return data

def clean_password(self):
    data = self.cleaned_data['password']
    try:
        validate_password(data, self.instance)
    except forms.ValidationError as error:
        self.add_error('password', error)
    return data

cleaned_data also delivers nothing here.

>Solution :

I don’t know what your validate_password method does, however your problem seems to be coming from the self.instance you’re passing as one of its parameters. Using self instead of self.instance would probably solve your problem.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading