我正在使用Angular AJAX調用將數據發送到我的Flask後端以進行自然語言處理。Python Flask從AngularJS檢索POST數據AJAX
AJAX代碼:
$scope.processText = function(){
$http({
method: "POST",
url: "http://127.0.0.1:5000/processText",
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
data: {
'message': "this is my message",
}
}).then(function successCallback(response){
console.log(response.data)
$scope.message = "";
});
}
我能夠檢索對象{消息:「這是我的消息」},但遺憾的是我不能鍵入request.data.message訪問密鑰。
瓶路線
@app.route('/processText', methods=['POST'])
def analyzeText():
if request.method == "POST":
data = json.loads(request.data)
return data #error : "dict is not callable"
return data.message #error : "'bytes' object has no attribute 'message'"
它就像一個魅力!非常感謝! – Danzeeeee