user Form error

11 views
Skip to first unread message

anchal agarwal

unread,
Jun 6, 2019, 1:50:50 PM6/6/19
to django...@googlegroups.com
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']

terry frank

unread,
Jun 6, 2019, 2:33:17 PM6/6/19
to django...@googlegroups.com
Hello,  from which repos ?

--
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 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.

Chetan Ganji

unread,
Jun 6, 2019, 3:53:07 PM6/6/19
to django...@googlegroups.com

anchal agarwal

unread,
Jun 7, 2019, 11:34:29 AM6/7/19
to django...@googlegroups.com

Thanks Chetan ...It worked !!

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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.

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages