2016-02-09 84 views
0

我正在嘗試使用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" , 
     }) 
+0

回溯添加 –

回答

0

沒有完全回溯我會假設它是因爲如果您在創建用戶之前嘗試設置密碼。

試着去做;

def done(self, form_list, **kwargs): 
     past_data = self.get_cleaned_data_for_step('1') 
     passd=past_data(['password1']) 
     user = self.instance.save() 
     user.set_password(passd) 

     return render_to_response('app/successpage.html', { 
      'title':"Registration completed" , 
     }) 

編輯

的問題是在這之前,但上面的應該還是有效的。

你打電話past_data當它是一個字典我相信,通過get_cleaned_data_for_step返回,所以你需要做的passd=past_data.get('password1')

+0

不,didnt幫助。回溯添加 –

+0

@AlexeyKostopravkin正確的,問題出現之前,所以檢查我的更新 - 你的過去的數據是一個字典,所以你需要改變它。但要小心那個'set_password'調用,因爲我認爲我之前關於用戶必須存在的觀點仍然是正確的。 –

+0

根據意見完成更改(添加在問題代碼中)。 「NoneType」對象的錯誤更改沒有屬性「get」。添加了新的追溯。 –