django formwizard上一页验证

时间:2019-02-20 13:34:45

标签: django django-formwizard django-formtools

我刚刚制作了多页注册页面。 但是,当我单击“上一步”按钮时,它需要填写当前页面。 我希望它能够即使用户没有填写当前页面的形式也能够移动到上一页。 这是页面的视图。

from django.shortcuts import render, HttpResponseRedirect
from formtools.wizard.views import SessionWizardView
from django.contrib.auth.forms import User
from django.views.decorators.csrf import csrf_protect
from .forms import HiarcUserCreationForm1, HiarcUserCreationForm2, HiarcUserCreationForm3
from .models import HiarcUser

class SignupWizard(SessionWizardView):

    template_name = 'hiarc_registration/register.html'
    form_list = [HiarcUserCreationForm1, HiarcUserCreationForm2, HiarcUserCreationForm3]

    def done(self, form_list, **kwargs):        
        if self.request.method == 'POST':            

            data = {}
            for form in form_list:
                data.update(form.cleaned_data)  

            user = HiarcUser.objects.create_user(**data)   

        return render(self.request, 'hiarc_registration/done.html', {
            'form_data' : [form.cleaned_data for form in form_list],
        })

0 个答案:

没有答案