Django FormWizard Dynamically Alter form_list

佐手、 提交于 2019-11-30 10:37:10

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!