Hi Anchal

PFA
https://stackoverflow.com/questions/9061846/attributeerror-at-registration-userform-object-has-no-attribute-save


.save() method is available on forms.ModelForm; not on forms.Form

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Jun 7, 2019 at 12:02 AM terry frank <otepate...@gmail.com> wrote:

> Hello,  from which repos ?
>
> On Thu, Jun 6, 2019 at 7:50 PM anchal agarwal <agarwalancha...@gmail.com>
> wrote:
>
>> 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
>> <https://groups.google.com/d/msgid/django-users/CAMT%3DisXLE0z7ADcBzB-LhDf%2BU9_ZNVrhitBAVrSDwQCSKEfNZg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/CACGjKra8_nF%2BcymQogX9Y0iQbNt0nG9mLWv6kfB_4OVJB-HC1Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACGjKra8_nF%2BcymQogX9Y0iQbNt0nG9mLWv6kfB_4OVJB-HC1Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMKMUjvyOVUrjO-X-iAQE4UwhEzOvMBtwryj0iy7xZceQmxguw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to