Flask查询字符串第二个参数返回null

时间:2014-12-07 22:06:07

标签: python flask query-string

我正在尝试从Flask中的查询字符串中获取2个值,但由于某些原因我无法理解,Flask的请求对象只能设法获取第一个值。

以下是一个例子:

@app.route('/whatishappening')
def what():
    please = request.args.get('please')
    work = request.args.get('work')

    return jsonify({'strange': (please, work)})

卷曲命令:

curl -i http://localhost:5000/whatishappening?please=god&work=already

request.args('work')返回null:

{
  "strange": [
    "god",
    null
  ]
}

非常感谢您的时间:)

1 个答案:

答案 0 :(得分:0)

&用于分叉进程。如果您将URL包装在引号中,您应该看到预期的输出。

$ curl -i "http://0.0.0.0:5000/whatishappening?please=god&work=already"
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 48
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Sun, 07 Dec 2014 23:04:18 GMT

{
  "strange": [
    "god",
    "already"
  ]
}