我正在使用django向导进行多表格注册,最终将是4或5页表格。但是我得到的验证错误可能与表单操作有关,我不知道如何解决。
错误似乎来自第282行:https://github.com/django/django-formtools/blob/master/formtools/wizard/views.py 但是我不清楚造成它的原因是什么?
(注意我使用的是django脆皮形式,但可能不相关)
views.py
class SignupWizard(SessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def done(self, form_list, **kwargs):
for form in form_list:
if isinstance(form, SignupForm):
user = form.save(self.request)
complete_signup(self.request, user, settings.ACCOUNT_EMAIL_VERIFICATION, settings.LOGIN_REDIRECT_URL)
else:
other_signup_form = form.save(commit=False)
user = self.request.user
other_signup_form.user = user
other_signup_form.save()
return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
signup_view = SignupWizard.as_view(SIGNUP_FORMS)
forms.py
class SignupForm(allauthforms.SignupForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.label_class = 'sr-only'
self.helper.layout = Layout(
Field('name', placeholder='Your Name'),
PrependedText('email', '<i class="fa fa-envelope-o"></i>', placeholder="Your Email",
autofocus=""),
PrependedText('password1', '<i class="fa fa-key"></i>', placeholder="Enter Password"),
Submit('sign_up', 'Sign up', css_class="btn btn-block btn-cta-primary"),
)
class SignupForm2(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
模板:
{% block inner %}
<h2 class="title text-center">Sign up now</h2>
<p class="intro text-center">It only takes 2 minutes.</p>
<div class="row">
{% crispy form %}
</div>
{% endblock %}