对Django上的HTTP请求和JSON消息进行故障诊断

问题描述 投票:0回答:1

好吧,所以我已经在这一段时间了,看起来我似乎无处可去。我正在使用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)
  1. 我收到了无法解码JSON的错误。所以我尝试了data = request.body[0]也没用。
  2. 有没有其他方法我可以测试我的服务器上的小更改,而无需执行Git push,Git Pull,Python -m compileall等等?我问的原因是因为我被教导通过练习这样做,我觉得有更好的方法。
  3. 我在哪里可以查看我的print data

任何帮助将受到高度赞赏。

javascript python django http ubuntu
1个回答
0
投票

原来我得到的data不适合JSON。我回去改变了发送数据作为json的请求,它运行得很好。

© www.soinside.com 2019 - 2024. All rights reserved.