是否可以从具有相同名称的查询字符串中获取值? [英] Is it possible to get values from query string with same name?

查看:33
本文介绍了是否可以从具有相同名称的查询字符串中获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以从这个查询字符串中获取值?

I want to know if it's possible to get values from this query string?

'?agencyID=1&agencyID=2&agencyID=3'  

为什么我必须使用这样的查询字符串?
我有一个带有 10 个复选框的表单.我的用户应该向我发送他/她感兴趣的新闻机构的 ID.以便查询包含多个同名值的字符串.新闻机构的总数是可变的,它们是从数据库中加载的.
我正在使用 Python Tornado 来解析查询字符串.

Why I have to use a query string like this?
I have a form with 10 check boxes. my user should send me ID of news agencies which he/she is interested in. so to query string contains of multiple values with the same name. total count of news agencies are variable and they are loaded from database.
I'm using Python Tornado to parse query strings.

推荐答案

阅读龙卷风文档,这似乎可以满足您的需求

Reading the tornado docs, this seems to do what you want

RequestHandler.get_arguments(name, strip=True)

返回一个列表具有给定名称的参数.如果参数不存在,则返回一个空列表.返回值始终为 unicode.

Returns a list of the arguments with the given name. If the argument is not present, returns an empty list. The returned values are always unicode.

就这样

ids = self.get_arguments('agencyID')

请注意,这里我使用了 get_arguments,还有一个 get_argument 但它只获取一个参数.

Note that here i used get_arguments, there is also a get_argument but that gets only a single argument.

您可以使用

query = self.request.query

这篇关于是否可以从具有相同名称的查询字符串中获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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