javascript - 对 Django 上的 HTTP 请求和 JSON 消息进行故障排除
问题描述
好的,所以我已经做了一段时间了,但似乎我没有取得任何进展。我正在使用 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)
- 我收到无法解码 JSON 的错误。所以我尝试
data = request.body[0]
了它也没有工作。 - 有没有其他方法可以在我的服务器上测试小的更改而无需执行 Git 推送、Git Pull、Python -m compileall 等?我问的原因是因为我是通过实践教我这样做的,我觉得有更好的方法。
- 我在哪里可以检查我的
print data
?
任何帮助将不胜感激。
解决方案
原来data
我得到的不是 JSON 合适的。我回去更改了将数据作为 json 发送的请求,并且效果很好。
推荐阅读
- javascript - 我可以让两个更改事件侦听器互相触发吗?
- asp.net-core - ASP.NET CORE Kendo UI TextBoxFor 无法加载
- python - 在 Django 中使用循环将字典添加到另一个字典中
- performance - 在 Docker 中覆盖 ENTRYPOINT 时停止 Apache2 的速度要慢得多
- excel - 如果列表中的值匹配,则在下面插入相应的值
- reactjs - React firebase 无法取消订阅监听器
- google-analytics - 谷歌分析不会在任何仪表板中显示任何数据
- recaptcha - 发布到不同服务器时的 Google recaptcha
- java - 有没有办法避免在 if else 块中重复方法调用?
- android-studio - 使用 Android Studio 4.0 创建布局检查器 *.li 文件