【问题标题】:Flask not recognising two URL parametersFlask 无法识别两个 URL 参数
【发布时间】:2015-01-28 00:30:07
【问题描述】:

我正在尝试向使用 Flask 路由的 URL 发送两个参数。

如果我这样做:

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')])

有人知道我做错了什么吗?我感觉某处一定有什么愚蠢的错误或误解,但我找了一个小时也没找到。

【问题讨论】:

  • 你错过了 shell 上的 [1] <process number>[1]+ Exit <exit code> 输出..

标签: python rest flask


【解决方案1】:

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

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

【讨论】:

  • 啊,太好了,现在可以了。谢谢。很高兴我现在问,否则我会摸不着头脑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
  • 2015-12-07
  • 1970-01-01
  • 2019-07-14
  • 2013-08-09
  • 2015-02-17
  • 1970-01-01
相关资源
最近更新 更多