Django FormWizard。需要set_password

时间:2016-02-09 14:58:41

标签: python django django-formwizard

我正在尝试使用>> runtests partest Error using matlab.unittest.TestSuite.fromFile (line 163) The class partest has no property or method named 'getLevel'. 为新用户注册。所有验证完成后,我目前在传递密码时遇到问题。 我尝试过很多方法,但总是会出错。回溯如下:

回溯:

getLevel()

forms.py

FormWizard

views.py

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'

1 个答案:

答案 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')