Flask无法识别两个URL参数

时间:2014-11-29 15:48:13

标签: python rest flask

我尝试将两个参数发送到使用Flask路由的网址。

如果我这样做:

curl -i http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell

然后我的代码是:

@application.route('/api/journeys/count', methods=['GET'])
def journeys():
    print request.args
    startStationName = request.args.get('startStationName')
    endStationName = request.args.get('endStationName')

应该打印一个定义了startStationNameendStationName的字典。

但是,似乎只收到第一个参数:

ImmutableMultiDict([('startStationName', u'Hansard Mews, Shepherds Bush')])

有人知道我做错了什么吗?我觉得某处肯定会有某种愚蠢的错误或误解,但我一直在寻找一个小时但却无法找到它。

1 个答案:

答案 0 :(得分:1)

您的 shell 会将&解释为put the command in the background character。为防止这种情况,请引用整个网址:

curl -i "http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell"
相关问题