好的,所以我已经花了一段时间了,看来我什么也没得到。我正在使用Nginx和uwsgi运行Django应用。我有一个http.post,我甚至试图阅读我不断出错的项目。
这就是我的JS代码:
$scope.receipt_pay_update = function(items)
{
response = confirm("Do you want to continue with the changes?");
if(!response){
return;
}
var data = {
'items': items,
'time_now': moment().format("YYYY-MM-DD")
};
items.showmessage = true;
console.log(data)
$http.post("/foodhub/dashboard/receipt_pay_modal_update", data,{
data: JSON
}).
success(function(data,status,headers,config){
$scope.alertclass = 'alert-success';
$scope.save_message_farmer = "Succcessfully update payment"
console.log("SAVED!")
}).
error(function(data,status,headers,config){
$scope.alertclass = 'alert-danger';
$scope.save_message_farmer= "Failed to update inventory, please try again"
})
}
这是我的views.py的样子:
@login_required
def receipt_pay_modal_update(request):
import sys
reload(sys)
sys.setdefaultencoding('utf8')
data = json.loads(request.body)['items']
print data
rec = ReceiverActions.objets.get(identifier = data[0]['identifier'])
rec['paid_check'] = data[0]['paid_status']
rec['date_paid'] = data[0]['paid_date']
rec.save()
return HttpResponse(status=status.HTTP_200_OK)
data = request.body[0]
,该方法也无效。print data
?任何帮助将不胜感激。
答案 0 :(得分:0)
结果发现我得到的data
不适合JSON。我回过头来,更改了将数据作为json发送的请求,它运行良好。