Python - 阅读复选框 [英] Python - reading checkboxes

查看:117
本文介绍了Python - 阅读复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个具有通用名称和个别变量(ID)的复选框。
我如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆