POST 多个复选框值龙卷风
我正在摆弄一个龙卷风网络应用程序,我需要一些帮助。我有多个同名的复选框,我想发布所选复选框的值。
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
我可以使用 javascript pre-POST 获取每个值,但在 python(龙卷风)端获取此列表时遇到问题。我只得到最高的选定值。
在 python 方面,它看起来像:
...
def post(self):
email = self.get_argument("email")
activity = self.get_argument("activity")
I am messing around with a tornado web app with which I need a bit of help. I have multiple checkboxes with the same name and I would like to POST the values of the selected one.
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
I can get the values of each with javascript pre-POST but am having troubles getting this list on the python (tornado) side. i only get the highest selected value.
on the python side it looks like:
...
def post(self):
email = self.get_argument("email")
activity = self.get_argument("activity")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以让多个标签具有相同的 name 属性,但
id
属性必须是唯一的 - 这里,它们不是(除非出现的每一个相同的DB_BASED_ID
都以某种方式被替换为不同的值?但是为什么不显示这些东西实际上是不同的,因为它们确实出现在真实的 HTML 中?!),使得这个 HTML 无效并容易出现各种问题。一旦此问题得到解决,在这些处理程序方法中, self.request.arguments['activity'] (如果该字符串键存在于所述目录中)将是所有非空值的列表名为
'activity'
的输入(如果有)。It's fine to let multiple tags have the same name attribute, but the
id
attributes must be unique -- here, they're not (unless each of those occurrences of the identicalDB_BASED_ID
is somehow meant to be replaced with a different value? But then why not show the things actually distinct, as they do appear in the real HTML?!), making this invalid HTML and subject to all sorts of problems.Once this problem is fixed, in those handler methods,
self.request.arguments['activity']
(if that string key is present in said directory) will be a list of non-empty values for all inputs named'activity'
(if any).这也可以通过动态演示和演示的循环来完成。收藏。假设,如果您在 GET 方法中提供要检查的列表,则它可以像 HTML 中一样显示:
POST 方法可以迭代该列表,收集每个列表并创建一个列表输入。它稍微更具技术性,但我无法使上述解决方案发挥作用。
这将 Tornado 的模板 (jinja2) 功能与一些 html 结合起来,形成一个简单的界面。可行&快速,诚然不是最好的生产解决方案。希望这有帮助!
This can also be accomplished with a loop for dynamic presentation & collection. Hypothetically, if you provide a list to check from in the GET method, it can be displayed like so in HTML:
The POST method can iterate that list, collect for each and create a list input. It's slightly more technical but I could not make the aforementioned solution work.
This combines Tornado's templating (jinja2) feature with some html for a simple interface. Doable & quick, admittedly not the best production solution. Hope this helps!