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

时间:2015-12-01 05:21:27

标签: django django-templates django-views django-formwizard

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

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

由于设计发生了变化,我现在必须整合表单向导。如何通过表单向导将上述变量'current_account'和'accounts'传递给特定的html,以便html正确呈现。如何将变量返回到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

1 个答案:

答案 0 :(得分:0)

添加上下文使用

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