Hello,
I am making a simple user form but my form data is not saving.It is showing
this error
'UserForm' object has no attribute 'save'
Here is my code. Please tell me where i am wrong
views.py
class UserFormView(View):
form_class=UserForm
template_name='music/registration_form.html'

#display blank form
def get(self , request):
form=self.form_class(None)
return render(request,self.template_name,{'form':form})

#process from data
def post(self, request):
form=self.form_class(request.POST)

if form.is_valid():
user=form.save(commit=False)

#cleaned (normalized) data
username=form.cleaned_data['username']
password=form.cleaned_data['password']
user.set_password(password)
user.save()

#returns User objects if credentials are correct

user=authenticate(username=username,password=password)

if user is not None:

if user.is_active:
login(request,user)
return redirect('music:index')
return render(request,self.template_name,{'form':form})

forms.py
from django import forms
from django.contrib.auth.models import User

class UserForm(forms.Form):
password=forms.CharField(wiget = forms.PasswordInput)
class Meta:
model=User
fields=['username','email','password']

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMT%3DisXLE0z7ADcBzB-LhDf%2BU9_ZNVrhitBAVrSDwQCSKEfNZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to