如何在表单向导中将值传递给 html?

How do you pass values to an html in Form Wizard?

我目前有一个视图,我在函数末尾通过 return 渲染器传递参数,如下所示:

return render(request, 'a.html', 
    {'form': form,
    'current_account': current_account,
    'accounts': accounts},
)

由于设计上的变化,我现在必须集成表单向导。如何通过表单向导将上述变量 'current_account' 和 'accounts' 传递给特定的 html,以便 html 正确呈现。我如何 return 将变量 a.html?

这里是我修改的表单精灵功能:

class UserAccounts(SessionWizardView):
    form_list = [FormA, FormB]
    ... more code ...


    def get_form(self, step=None, data=None, files=None):
        form = super(VerifyUserAccounts, self).get_form(step, data, files)

        # determine the step if not given
        if step is None:
            step = self.steps.current
            accounts = []

            for item in number_of_accounts_wo_at:
                accounts.append(item)

                current_account = accounts[0]
                accounts = accounts[1:]

        return form

要添加上下文,请使用

def get_context_data(self, form, **kwargs):
    context = super(UserAccounts, self).get_context_data(form=form, **kwargs)
    if self.steps.current == 'my_step_name':
        context.update({'variable key': variable value})
    return context

如需进一步阅读,请单击 here