[英]Troubleshooting HTTP request and JSON message on Django
Okay, so I have been going at this for a while and it doesn't seem like I am getting anywhere. 好吧,所以我已经花了一段时间了,看来我什么也没得到。 I am running a Django app with Nginx and uwsgi.
我正在使用Nginx和uwsgi运行Django应用。 I have an http.post and I am trying to even read the items which I keep getting errors for.
我有一个http.post,我甚至试图阅读我不断出错的项目。
This is what my JS code looks like : 这就是我的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"
})
}
This is what my views.py looks like: 这是我的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]
which also didn't work. data = request.body[0]
,但该方法也无效。 print data
? print data
? Any help would be highly appreciated. 任何帮助将不胜感激。
Turns out the data
I was getting was not JSON appropriate. 原来我得到的
data
不适合JSON。 I went back and changed the request to send data as a json and it worked perfectly. 我返回并更改了将数据作为json发送的请求,它运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.