【问题标题】:How do you pass values to an html in Form Wizard?如何在表单向导中将值传递给 html?
【发布时间】:2015-12-01 05:21:27
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    添加上下文使用

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2018-12-01
      • 2021-07-29
      • 2015-08-31
      • 1970-01-01
      相关资源
      最近更新 更多