Using different templates with django form wizard

I looked at the documentation, and I'm not quite sure how to use different templates for each step ...

I looked at the source code and it seems that the template name is hard-coded:

class WizardView(TemplateView):
    """
    The WizardView is used to create multi-page forms and handles all the
    storage and validation stuff. The wizard is based on Django generic
    class based views.
    """
    storage_name = None
    form_list = None
    initial_dict = None
    instance_dict = None
    condition_dict = None
    template_name = 'formtools/wizard/wizard_form.html'

...........

The docs say something about mixins, but I'm not sure how to use them since I just started with django ...

thank


UPDATE:

I looked further into the source code and realized that there was a method get_template_names.

I tried:

class AddWizard(SessionWizardView):
        def get_template_names(self, step):
                if step == 0:
                        return 'business/add1.html'
                return 'business/add2.html'
        def done(self, form_list, **kwargs):
                return render_to_response('business/done.html', {
                        'form_data': [form.cleaned_data for form in form_list],
                })

But the error turned out:

get_template_names() takes exactly 2 arguments (1 given)

+3
source share
1 answer

get_template_namesdoes not accept arguments. You cannot just define a new argument for the function you want to accept and hope that the infrastructure passes it! (for your future troubleshooting)

WizardView, , self.steps.current, get_template_names, , .

class AddWizard(SessionWizardView):
        def get_template_names(self):
            return ['step_{0}_template.html'.format(self.steps.current)]

, current , - - , " X".

+8

All Articles