Django表单向导'NoneType'对象没有属性'rsplit'错误

时间:2015-10-10 02:59:04

标签: python django forms formwizard

希望有人可以提供帮助,我一直在为项目尝试表单向导,并且一直在密切关注文档,但不断收到此错误:

  

'NoneType'对象没有属性'rsplit'

forms.py:

from django import forms


class ContactForm1(forms.Form):
    subject = forms.CharField()
    sender = forms.CharField()


class ContactForm2(forms.Form):
    message = forms.CharField()

views.py:

class ContactWizard(WizardView):
    def done(self, form_list, **kwargs):
        return render_to_response('done.html', {
            'form_data': [form.cleaned_data for form in form_list],
        })

和urls.py(atestapp是'woo')

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^woo/', ContactWizard.as_view([ContactForm1, ContactForm2]))
]

回溯:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/woo/

Django Version: 1.8.4
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'formtools')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:

    File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
      132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Python34\lib\site-packages\django\views\generic\base.py" in view
      71.             return self.dispatch(request, *args, **kwargs)
    File "C:\Users\pdelarosa\AppData\Roaming\Python\Python34\site-packages\formtools\wizard\views.py" in dispatch
      235.             getattr(self, 'file_storage', None))
    File "C:\Users\pdelarosa\AppData\Roaming\Python\Python34\site-packages\formtools\wizard\storage\__init__.py" in get_storage
      13.         storage_class = import_string(path)
    File "C:\Python34\lib\site-packages\django\utils\module_loading.py" in import_string
      21.         module_path, class_name = dotted_path.rsplit('.', 1)

    Exception Type: AttributeError at /woo/
    Exception Value: 'NoneType' object has no attribute 'rsplit'

每当我转到woo / url时,它只显示非类型错误拆分。我已经尝试重做整个事情,但仍然得到相同的错误。希望有人可以提供帮助。

1 个答案:

答案 0 :(得分:1)

尝试继承WizardView

,而不是继承SessionWizardView
from formtools.wizard.views import SessionWizardView

class ContactWizard(SessionWizardView):
    ...

文档对此并不十分清楚,但在大多数情况下,您不应直接将WizardView子类化 - 而是应该使用多个子视图:

SessionWizardView CookieWizardView NamedUrlWizardView等。