python - object has no attribute 'clean_data' error -


i keep on getting object has no attribute when cleaning data. error occurs when try post form register user.

while have used django built in registration view , form, decided use built 1 since wanted make easier use extended custom user model later. views:

def register(request):  if request.method == 'post':     user_form = userregistrationform(request.post)     if user_form.is_valid():          new_user = user_form.save(commit=false)          new_user.set_password(             user_form.clean_data['password'])          new_user.save()          profile = profile.objects.create(user=new_user)          return render(request,              'account/register_done.html',              {'new_user':new_user}) else:     user_form = userregistrationform()  return render(request,                  'registration.html',              {'user_form': user_form}) 

forms:

from django import forms django.contrib.auth.models import user  django.contrib.auth.forms import usercreationform      class userregistrationform(forms.modelform):      password = forms.charfield(label='password',         widget=forms.passwordinput)     password2 = forms.charfield(label='repeat password',          widget=forms.passwordinput)  class meta:     model = user     fields = ('username', 'first_name',         'email')      def clean_password2(self):         cd = self.clean_data         if cd['password'] != cd['password2']:             raise forms.validationerror('passwords don\'t match.')         return cd['password2'] 


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -