Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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 根据选中的复选框值显示内容_Python_Django - Fatal编程技术网

Python 根据选中的复选框值显示内容

Python 根据选中的复选框值显示内容,python,django,Python,Django,我正在尝试根据选中的复选框值检索信息。现在,我已经根据选中的复选框相应地显示了内容。但是,它仅适用于一个选中的复选框。如果我选中多个复选框,它将返回最后选中的复选框 我知道我必须使用request.POST.getlist('name')来传递多个复选框值。当我这样做时,它什么也不显示 我想展示在选定的一周内参加过课程的学生的姓名 下面是我的示例代码: Views.py def filterWeek(request): qs = MarkAtt.objects.all

我正在尝试根据选中的复选框值检索信息。现在,我已经根据选中的复选框相应地显示了内容。但是,它仅适用于一个选中的复选框。如果我选中多个复选框,它将返回最后选中的复选框

我知道我必须使用request.POST.getlist('name')来传递多个复选框值。当我这样做时,它什么也不显示

我想展示在选定的一周内参加过课程的学生的姓名

下面是我的示例代码:

Views.py

    def filterWeek(request):


        qs = MarkAtt.objects.all()

        week_checked = request.GET.get('week_check')

        if week_checked:
            # week_mchecked = request.POST.getlist('week_check') #not working, display nothing
#qs = qs.filter(week_in=week_mchecked)
            qs = qs.filter(week=week_checked)

        context={
        'queryset' : qs
        }
        return render(request, "filter.html", context)
模板:

       <form method="GET" action=".">


 <input type="checkbox" id="week_check" name="week_check" value="1"/> Week 1

 <input type="checkbox" id="week_check" name="week_check" value="2"/> Week 2

<input type="checkbox" id="week_check" name="week_check" value="3"/> Week 3

</form>

第一周
第2周
第3周

希望你们中的任何人都能帮助我。非常感谢。

我刚刚尝试改变这一点:

  week_mchecked = request.POST.getlist('week_check') 

它正在发挥作用。显然,我刚刚意识到我的表单方法是GET而不是POST

week_mchecked = request.GET.getlist('week_check')