小编jes*_*jes的帖子

在django中处理单个html表单的多个输入值

我有一个带有3个输入和步骤按钮的html表单.

  • 1 步用户必须把名字和按下按钮1
  • 2 第二步骤,用户必须把最后一个名称,然后按按钮2
  • 3 第三步,用户必须把电子邮件,并按下按钮,最后3

每当用户按下任何按钮,然后转到下一个html步骤.

我希望views.py在用户按任何按钮的任何时候逐步处理输入,而不是在最终提交中一起处理输入.

我尝试使用此代码在views.pydjango后端获取输入,但我没有得到任何东西views.py(如果我更改按钮类型button,submit然后我得到结果坚果刷新页面,我不能转到第2步)

views.py

if request.method == 'POST' and 'first_step' in request.POST:
    print '1'
    firstname= request.POST.get('firstname')
if request.method == 'POST' and 'second_step' in request.POST:
    print '2'
    lastname= request.POST.get('lastname')
if request.method == 'POST' and 'final_step' in request.POST:
    print '3'
    email= request.POST.get('email')
Run Code Online (Sandbox Code Playgroud)

这是我的HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <title>Form wizard with circular tabs</title>

    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head> …
Run Code Online (Sandbox Code Playgroud)

html javascript python django django-views

9
推荐指数
1
解决办法
2427
查看次数

标签 统计

django ×1

django-views ×1

html ×1

javascript ×1

python ×1