Python - 阅读复选框 [英] Python - reading checkboxes
问题描述
我如何在python中读取它们作为列表?
现在我正在使用
checkbox = request.POST [common_name]
它不能正常工作,checkbox变量仅存储最后一个复选框,而不是任何列表或任何东西。
如果您使用WebOB,request.POST.getall('common_name')将为您提供名称为common_name的所有POST变量的列表。有关更多信息,请参阅 WebOB 文档。
但是你不是 - 你使用Django。有关几种方法,请参阅 QueryDict 文档这个 - request.POST.getlist('common_name')
是一种方法。
I have a few checkboxes with common name and individual variables (ID). How can I in python read them as list? Now I'm using
checkbox= request.POST["common_name"]
It isn't work properly, checkbox variable store only the last checked box instead of any list or something.
If you were using WebOB, request.POST.getall('common_name') would give you a list of all the POST variables with the name 'common_name'. See the WebOB docs for more.
But you aren't - you're using Django. See the QueryDict docs for several ways to do this - request.POST.getlist('common_name')
is one way to do it.
这篇关于Python - 阅读复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!