我正在嘗試使用FormWizard
爲新用戶進行註冊。在完成所有驗證後,我目前在傳遞密碼方面存在問題。 我試圖做很多方法,但總是得到一個錯誤。回溯列出如下:Django FormWizard。需要set_password
回溯:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\formtools\wizard\views.py" in dispatch
237. response = super(WizardView, self).dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\formtools\wizard\views.py" in post
300. return self.render_done(form, **kwargs)
File "C:\Python27\lib\site-packages\formtools\wizard\views.py" in render_done
357. **kwargs)
File "C:\Users\U-60.DOM\Source\Repos\Casting\Casting\Casting\Casting\app\views.py" in done
940. passd=past_data.get('password1')
Exception Type: AttributeError at /registration_steps
Exception Value: 'NoneType' object has no attribute 'get'
forms.py
class ApplicantForm1(forms.ModelForm):
password1 = forms.CharField(
label='Password',
widget=forms.PasswordInput
)
password2 = forms.CharField(
label='confirm',
widget=forms.PasswordInput
)
def clean_password2(self):
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError('Passwords dont match')
return password2
class Meta:
model = ExtUser
fields = ['email','firstname', 'lastname', 'middlename', 'date_of_birth', 'gender', 'family_position',
'driver_license', 'driver_license_category',
]
views.py
class ApplicantWizard(SessionWizardView):
def get_template_names(self):
return [TEMPLATES_REG[self.steps.current]]
def get_form_instance(self, step):
# if self.instance is None:
# self.instance = ExtUser()
return self.instance
def done(self, form_list, **kwargs):
past_data = self.get_cleaned_data_for_step('1')
passd=past_data.get('password1')
user = self.instance.save()
user.set_password(passd)
return render_to_response('app/successpage.html', {
'title':"Registration complited" ,
})
回溯添加 –