我正在使用我的API中的第一个POST方法路由。出于某种原因,当我通过url http://test.com/test?stuff=wee将变量传递给它时,Flask会抛出错误,就像没有通过的东西一样。
代码:
@app.route('/test', methods = ['POST'])
def testindex():
stuff = request.args.get('stuff')
response_message = "success"
response_data = stuff
errors = "None"
response = {
'response message' : response_message,
'response data': response_data,
'errors' : errors
}
js = json.dumps(response)
resp = Response(js, status=200, mimetype='application/json')
return resp
卷曲:
curl -H "Content-Type: application/json" -X POST -d '{"stuff":"wee"}' http://test.com/test?stuff=wee
响应:
{"errors": "None", "response data": null, "response message": "success"}
帮助?
答案 0 :(得分:2)
request.args.get
用于从GET获取参数。你需要request.form
。