我有一个烧瓶应用,其中有一个端点为:
@app.route('/restaurant/<restaurant_id>', methods=['GET', 'POST'])
def detail(restaurant_id=None):
if request.method == 'GET':
#something
elif request.method == 'POST':
print jsonify(request.get_json(force=True)) #This doesn't work if I set content type as applicaiton/json
comments = [request.form['comment']] #this works if I set content type as form-data
# something
return Response(json.dumps({
'success': True,
'response': json_docs
}), status=200, content_type='application/json')
出于某种原因,我将无法在将application/json
作为Content-Type
作为JSON发布时读取该数据。 print命令只返回None
。我如何阅读Json数据?
答案 0 :(得分:0)
request.get_json()
返回JSON,因此jsonify
应该将其转回JSON。评论应为request.get_json(force=True)
。希望这会有所帮助。