2
我在我的API中处理我的第一个POST方法路由。由于某种原因,当我通过url http://test.com/test?stuff=wee将变量传递给它时,Flask会抛出像东西没有通过的错误。烧瓶不接收来自HTTP POST的数据
代码:
@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"}
帮助?
将其更改为var = request.get_json()。get('stuff',''),效果很好。谢谢。 – 2015-04-02 18:05:50