我正在尝试在 django 中实现表单向导。这些步骤按预期工作,但在提交最终表单(第二步)后,未命中完成功能。我无法找到原因。请直接。以下是我的代码,
表格.py
from django import forms
class FormStepOne(forms.Form):
name = forms.CharField(max_length=100)
last_name = forms.CharField(max_length=100)
phone = forms.CharField(max_length=100)
email = forms.EmailField()
class FormStepTwo(forms.Form):
otp = forms.CharField(max_length=100)
视图.py
from django.shortcuts import render
from .forms import FormStepOne, FormStepTwo
from formtools.wizard.views import SessionWizardView
from django.http import HttpResponseRedirect
# Create your views here.
class FormWizardView(SessionWizardView):
template_name = 'done.html'
form_list = [FormStepOne, FormStepTwo]
def done(self, form_list, **kwargs):
print('done')
return render(self.request, 'home.html', {'form_data':[form.cleaned_data for form in form_list],})
# return HttpResponseRedirect('/home/')
def process_step(self, form):
# print(self.get_form_step_data(form)['0-email'])
# print(self.steps.current)
if self.steps.current == '0':
print('send mail to ' + self.get_form_step_data(form)['0-email'])
else:
print('verify the entered otp')
我想在第一步提交后用 otp 发送邮件,然后在第二步中我要求在第一步发送的 otp 进行验证。默认情况下,在提交最后一步后,页面会重定向到第 1 步。为什么?