zoukankan      html  css  js  c++  java
  • 前端添加复选框checkbox 提交到django后台处理

    根据前端勾选的复选框 提交勾选的数据到后台处理

    che.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    
    
    <form action="" method="POST"> {% csrf_token %}
    
            <table>
            <thead>
            <th>1</th>
            <th>2</th>
            <th>3</th>
            <th>4</th>
            </thead>
    {#    <form action="" method="POST"> {% csrf_token %}#}
        {% for i in a %}
             <tbody>
             <td><input type="checkbox" value="{{ i }}" name="check_box_list" >{{ i }}</td>
             <td>234</td>
            </tbody>
    
        {% endfor %}
        </table>
    <input type="submit" value="提交"/>
    </form>
    {#<input type="checkbox" value="1" name="check_box_list"/>1#}
    {##}
    {#<input type="checkbox" value="2" name="check_box_list"/>2#}
    {##}
    {#<input type="checkbox" value="3" name="check_box_list"/>3#}
    {##}
    {#<input type="submit" value="提交"/>#}
    
    
    
    </body>
    </html>

    views.py

    def che(request):
        if request.method=="POST":
            check_box_list = request.POST.getlist('check_box_list')
            if check_box_list:
                print(check_box_list)
                return HttpResponse("ok")
            else:
                print("fail")
                return HttpResponse("fail")
        else:
            a = [1,2,3,4]
            return render(request,'che.html',{'a':a})

    url.py

        url(r'^che/', views.che ,name="che"),

    具体应用  见计划任务管理平台源码 

  • 相关阅读:
    VMware安装Centos7超详细过程
    LVS+Keepalived小试牛刀
    Spring入门之AOP篇
    Spring学习笔记及资源
    Spring入门第一例
    Mybatis学习手记(二)
    Mybatis学习手记(一)
    java web 开发入门实例
    关于JAVA编译时找不到自定义包的问题
    Java 学习笔记及资源
  • 原文地址:https://www.cnblogs.com/dribs/p/6932353.html
Copyright © 2011-2022 走看看