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

Django form wizard 'NoneType' object has no attribute 'rsplit' error

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

'NoneType' object has no attribute '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(astapp是'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 它只显示非类型错误拆分。我试过重做整个事情,但仍然遇到同样的错误。希望有人能帮忙。

不要子类化 WizardView,尝试子类化 SessionWizardView:

from formtools.wizard.views import SessionWizardView

class ContactWizard(SessionWizardView):
    ...

文档对此不是很清楚,但在大多数情况下,您不应该直接子类化 WizardView - 相反,您应该使用许多子视图:

SessionWizardView CookieWizardView NamedUrlWizardView