Python Bottle如何读取请求参数

mar*_*cho 7 python bottle http-request

我正在使用http://dingyonglaw.github.com/bootstrap-multiselect-dropdown/#forms显示带有多个复选框的下拉列表.

<li>
  <label>
    <input type="checkbox" name="filters" value="first value">
    <span>First Value</span>
  </label>
</li>

<li>
  <label>
    <input type="checkbox" name="filters" value="second value">
    <span>Second Value</span>
  </label>
</li>
Run Code Online (Sandbox Code Playgroud)

这是结果URL:

http://example.com/search?filters=first+value&filters=second+value
Run Code Online (Sandbox Code Playgroud)

在服务器端(瓶子):

terms = unicode (request.query.get ('filters', ''), "utf-8")
Run Code Online (Sandbox Code Playgroud)

只会给我"第二价值"并忽略"第一价值".有没有办法收集所有'过滤器'值?

Mar*_*ers 11

请改用该request.query.getall方法.

FormsDict是MultiDict的子类,可以为每个键存储多个值.标准字典访问方法只返回单个值,但MultiDict.getall()方法返回特定键的所有值的(可能为空)列表.