python - Django Forms 重定向处理向导中的步骤

标签 python django django-forms

我正在尝试在处理表单后检查一个步骤。它有 4 个具有不同值的单选按钮,当按下除第 4 个选项之外的任何选项时,我希望它直接重定向到向导之外的静态页面。目前,我正在努力寻找一种方法,允许我在 done() (流程中太晚)和 render() (之前调用)之外执行此操作页面上的表单已处理)。还有其他人在 Django 表单向导中获得了实现或正确的方法来允许重定向吗?

类似 process_step() 的方法本来是完美的方法,但无法在其中返回重定向。

我正在查看的文档

https://docs.djangoproject.com/en/1.7/ref/contrib/formtools/form-wizard/

最佳答案

您可以重写WizardView的函数render_next_step,如下所示:

views.py 的表单向导类中添加:

def render_next_step(self, form, **kwargs):
    if self.steps.current == 'your_step':
        data = form.cleaned_data
        if data['your_radio1'] or data['your_radio2'] or data['your_radio3']:
            return render_to_response('your_template.html')
    return super().render_next_step(form, **kwargs)

关于python - Django Forms 重定向处理向导中的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54594486/

相关文章:

ids 的 Django 列表作为表单字段

php - 从本地 PHP 脚本运行远程 python 脚本

python - 无法从外部进程读取 PTY(伪终端文件)

django - 在 Django 中使用 AuthenticationForm

django - 无法显示 django-debug-toolbar

python - 如何在Django中将对象从 "default"DB复制到另一个具有相同结构的DB

python - django-webtest 和 selenium 之间的区别

python - 将 Pandas 日期时间列 yyyy-mm-dd 转换为 YYYYMMDD

python - 如何更改 GridSearchCV.best_estimator_ 的 n_jobs 参数

python - Django 多标签字段