如何从Pylons中的URL获取具有相同名称的多个参数? [英] How to get multiple parameters with same name from a URL in Pylons?
问题描述
因此,不幸的是,我发现自己需要修改现有的Pylons应用程序以处理提供多个具有相同名称的参数的URL.类似于以下内容... domain:port/action?c = 1& v = 3& c = 4
So unfortunately I find myself in the situation where I need to modify an existing Pylons application to handle URLs that provide multiple parameters with the same name. Something like the following... domain:port/action?c=1&v=3&c=4
按常规方式可以通过这种方式访问参数...
Conventionally the parameters are accessed this way...
from pylons import request
c = request.params.get("c")
#or
c = request.params["c"]
在两种情况下,这都将返回"4"作为值,因为在这些情况下,忽略最后一个值之外的所有值似乎是标准行为.我真正需要的是能够同时访问这两者.我尝试打印出request.params并得到了类似的东西...
This will return "4" as the value in either case, because ignoring all but the last value seems to be the standard behavior in these situations. What I really need though, is to be able to access both. I tried printing out request.params and get something like this...
NestedMultiDict([(u'c', u'1'),(u'v', u'3'),(u'c', u'4')])
我还没有找到索引或访问c的第一个值的方法.
I haven't found a way to index into it, or access that first value for c.
我找到了与此问题相关的类似问题,但使用PHP可以解决:
I found a similar question relating to this problem, but solved with PHP:
按照这些思路进行工作对我来说很好,但是也许一些适合Pylons的Python代码.以前有没有人处理过类似的事情?
Something along these lines would work well for me, but maybe some Python code that would fit into Pylons. Has anyone dealt with something like this before?