Flask不能识别两个URL参数 [英] Flask not recognising two URL parameters
问题描述
如果我这样做的话:
pre>
curl -i http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell
然后我的代码是:
<$ p $打印请求.args $ b $打印请求.args $($) b startStationName = request.args.get('startStationName')
endStationName = request.args.get('endStationName')
应该打印一个带有 startStationName
和 endStationName
的字典。
然而,只有第一个参数被接收:
$ $ $ $ $ $ $ $ $ ImmutableMultiDict([( 'startStationName',u'Hansard Mews,Shepherds Bush')])
有人知道我是什么是吗?错了?我有一种感觉,一定有某种愚蠢的错误或误解的地方,但我一直在寻找一个小时,无法找到它。
shell 将&
解释为 将命令放在后台字符中。为了防止这种情况,请引用整个URL:
curl -ihttp://127.0.0.1:5000/api/journeys / count?startStationName = Hansard%20Mews,%20Shepherds%20Bush& endStationName = Farringdon%20Lane,%20Clerkenwell
I'm trying to send two parameters to a URL routed with Flask.
If I do:
curl -i http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell
Then my code which is:
@application.route('/api/journeys/count', methods=['GET'])
def journeys():
print request.args
startStationName = request.args.get('startStationName')
endStationName = request.args.get('endStationName')
Should print a dict with startStationName
and endStationName
defined.
However, instead, only the first parameter seems to be received:
ImmutableMultiDict([('startStationName', u'Hansard Mews, Shepherds Bush')])
Anybody got any idea what I'm doing wrong? I have a feeling there must be some kind of stupid mistake or misunderstanding somewhere but I've been looking for an hour and can't find it.
Your shell interprets the &
as a put the command in the background character. To prevent this, quote the whole URL:
curl -i "http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell"
这篇关于Flask不能识别两个URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!