Django FormWizard动态更改form_list [英] Django FormWizard Dynamically Alter form_list

查看:111
本文介绍了Django FormWizard动态更改form_list的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单向导中遇到一些问题,也许有人可以点点头。根据docstring方法process_step:我可以动态改变self.form_list。所以,根据我的项目需求,我将表单添加到form_list。我附加的表单包含问题和答案: http://dpaste.com/hold/152201/

I'm having some issues with the form wizard, that maybe someone can shed some light on. According docstring in the method process_step: I can "dynamically alter self.form_list". So, based on my project needs, I'm appending forms to the form_list. The forms I'm appending contain questions and answers: http://dpaste.com/hold/152201/

问题是当两个人同时击中formwizard时,他们开始看到对方的问题和答案。我想我不明白process_step如何建议我可以动态地更改form_list,当这样做时,我修改另一个用户的表单列表。
form_list是访问者访问urls.py中定义的formwizard url的共享对象吗?我在apache2 / prefork / worker / mod_wsgi中看到这个问题,并在运行runserver的应用程序时。

The issue is that when 2 people hit the formwizard at the same time, they start to see each others questions and answers. I guess I don't understand how process_step suggests I can dynamically alter the form_list, when by doing so I'm modifying the form list of another user. Is the form_list a shared object among visitors hitting the formwizard url defined in urls.py? I've seen this issue under apache2/prefork/worker/mod_wsgi, and while running the app with runserver.

推荐答案

你使用FormWizard?如果你把它放在urls.py中,像docs这样说就可以缓存,我有这个问题了。只要把它放在如下视图中:

How do you use FormWizard? If you're putting it in urls.py like docs says then it could be cached, i had that issue couple of times. Just put it in a view like:

def my_view(request):
    return FormWizard(request)

更新:来自实际的示例

UPDATE: Example from real

def registration_wizard(request, template_name=None):
    rw = RegistrationWizard([RegistrationForm, 0])
    #hack formwizard to replace default template
    if template_name:
        rw.get_template = lambda x: template_name

    return rw(request)



here RegistrationWizard is a FormWizard subclass with dynamic form_list, [RegistrationForm, 0] is needed because if there's only one form at creation time, wizard won't get to form_list function. Template thing is pretty self-explanatory

这篇关于Django FormWizard动态更改form_list的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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