‘RegisterForm’ object has no attribute ‘is_valid’


This Is models.py

from django.db import models
class RegisterForm(models.Model):
    fname = models.CharField(max_length=100)
    lname = models.CharField(max_length=100)
    pno = models.CharField(max_length=100)
    email = models.EmailField(max_length=200)
    pass1 = models.CharField(max_length=100)
    pass2 = models.CharField(max_length=100)

This is my Views.py

from django.shortcuts import render
from .models import RegisterForm
# Create your views here.
def registerView(request):
    if request.method=='POST':
        fm = RegisterForm(request.POST)
        if fm.is_valid():
            fname = fm.cleaned_data['fname']
            lname = fm.cleaned_data['lanme']
            pno = fm.cleaned_data['pno']
            email = fm.cleaned_data['email']
            pass1 = fm.cleaned_data['pass1']
            pass2 = fm.cleaned_data['pass2']
            reg = RegisterForm.save(fname = fname,lname=lname,pno=pno,email=email,pass1=pass1,pass2=pass2)
            fm = RegisterForm()
        fm = RegisterForm()
    return render(request, 'register.html', {})

Request Method: POST

Request URL:

Django Version: 3.2

Exception Type: AttributeError

Exception Value: ‘RegisterForm’ object has no attribute ‘is_valid’

Exception Location: H:Djangoautheticationusersviews.py, line 7, in registerView


You have created model not a form
Now you have need to create forms.py in app

from django import forms
from .models import Profile

class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = ‘all

You can use all for all fields in model but you can put only choosed fields in form via tuple (‘field_name’,’field_name’)

Leave a Reply

Your email address will not be published. Required fields are marked *