Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中获取所选多个复选框的值_Python_Django_Python 3.x - Fatal编程技术网

Python 在Django中获取所选多个复选框的值

Python 在Django中获取所选多个复选框的值,python,django,python-3.x,Python,Django,Python 3.x,我正在用django构建一个应用程序。现在我面临着复选框的问题。我可以从request.POST.getlist(复选框[])检索值。但这是一份清单。然后我做了一个for循环,使用slug来获取价格,但在这里,我面临的问题是如何为每个复选框存储一个单独的变量。因为它是在循环中,对于不同的值,不可能使用不同的变量?我怎么做呢 在我的模型中,我有一张桌子,上面有多余的东西。它具有SSL、安全性和备份功能 如果选中SSL和安全复选框,那么由slug我将获得价格。但我希望将其添加到订单模型中,该模型具有

我正在用django构建一个应用程序。现在我面临着复选框的问题。我可以从request.POST.getlist(复选框[])检索值。但这是一份清单。然后我做了一个for循环,使用slug来获取价格,但在这里,我面临的问题是如何为每个复选框存储一个单独的变量。因为它是在循环中,对于不同的值,不可能使用不同的变量?我怎么做呢

在我的模型中,我有一张桌子,上面有多余的东西。它具有SSL、安全性和备份功能

如果选中SSL和安全复选框,那么由slug我将获得价格。但我希望将其添加到订单模型中,该模型具有SSL和安全性等字段

我完全糊涂了。我应该如何制作模型架构。通过托管,用户可以购买SSL、安全、备份或其中任何一种

def checkout(request):
    if request.method == "POST":
        extras_slugs = request.POST.getlist("checkbox[]")
        for slug in extras_slugs:

您应该在此处使用request.POST.getlist。这是我基于复选框存储考勤数据的示例

在以下观点中:

if request.method == "POST":
            id_list = request.POST.getlist('choices')
在html中

    <form  action="{% url 'submitattendance' %}" method="post" role="form">
                    {% csrf_token %}

  <table class="table table-hover">
    <thead>
      <tr>
        <th>Name</th>
        <th>Status</th>
        <th><input type="checkbox" align="center" onClick="toggle(this)"></th>
      </tr>
    </thead>
    <tbody>
    {% for attendance in attendances %}
      <tr {% if attendance.present %} style="background-color:green;"{% endif %}>
        <td>{{attendance.first_name}} {{attendance.last_name}}</td>
        <td>{{attendance.status}}</td>
        <td><input type="checkbox" name="choices" value="{{attendance.id}}" {% if attendance.present %} checked="checked"{% endif %} class="checkbox_delete"></td>
        <td><input type="hidden" name="attendances" value="{{attendance.id}}"></td>
       </tr>
    {% endfor %}
    </tbody>
  </table>


{%csrf_令牌%}
名称
地位
{出席人数占出席人数的%}
{{出席.名字}{{出席.姓氏}
{{出席情况.状态}
{%endfor%}
希望这有帮助