WizardView子窗体中的访问请求对象 [英] Access Request Object in WizardView Sublcass

查看:77
本文介绍了WizardView子窗体中的访问请求对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django-formtools,我有以下情况:

I'm using django-formtools and I have the following scenario:

class CreateCampaign(NamedUrlSessionWizardView):

    condition_dict={'rewards':show_reward_form,
            'user_conditionals':show_conditionals_form,
            'organizer_info': show_organizer_info_form(self.request.user)}

    def get_template_names(self):
        return [TEMPLATES[self.steps.current]]
    ....

如您所见,我需要通过请求对象将当前登录的用户传递给 show_organizer_form()函数。在这种情况下,如何访问请求对象?非常感谢。

As you can see I need to pass the currently logged in user to the show_organizer_form() function via the request object. How can I access the request object in this case? Thanks a lot.

推荐答案

所以,用户apollo13帮助我在django频道。以下是正确的方式:

So, user apollo13 helped me on the django channel. Here is how the correct way looks:

condition_dict={
            'rewards':show_reward_form,
            'user_conditionals':show_conditionals_form,
            'organizer_info': lambda w:(show_organizer_info_form(w.request.user)),
        }

请注意使用 lambda w

这篇关于WizardView子窗体中的访问请求对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆