【发布时间】:2016-03-01 22:13:49
【问题描述】:
我在 Django 中编码,我的前端使用这样的 Angularjs:
在 controller.js 中
$scope.reserve = {
reserve: {
duration: {
startTimeUnix: null,
startTime: "صبور باشید...",
endTime: null
},
service: null,
reserver: {
first_name: null,
last_name: null,
phone: null
}
},
block: {
duration: null
},
is_block: false,
taken_time: null,
staff: "صبور باشید..."
};
$scope.submitAdminTime = function() {
$http.post("/schedule/admin/block/", {
data: $scope.reserve
}, {
"headers": {
"Content-Type": "application/json"
}
})
.success(function(data) {
console.log(data);
});
};
在views.py中
@csrf_exempt
def admin_block_time(request):
try:
json_object = json.loads(request.body)
print('yes')
except ValueError:
print('no')
什么都不打印!
我不知道为什么json.loads() 根本不起作用!我发布了另一个问题here 并跟进了所有答案。
request.body
b '{
"reserve": {
"duration": {
"startTimeUnix": "",
"startTime": "\xd8\xb5\xd8\xa8\xd9\x88\xd8\xb1 \xd8\xa8\xd8\xa7\xd8\xb4\xdb\x8c\xd8\xaf...",
"endTime": "\xdb\xb1\xdb\xb3\xdb\xb9\xdb\xb4/\xdb\xb0\xdb\xb9/\xdb\xb0\xdb\xb4 \xdb\xb1\xdb\xb2:\xdb\xb2\xdb\xb0",
"endTimeUnix": 1448441400
},
"service": null,
"reserver": {
"first_name": "\xd9\x85\xd8\xb1\xdb\x8c\xd9\x85",
"last_name": "\xd9\x85\xd9\x88\xd8\xb3\xd9\x88\xdb\x8c",
"phone": "09124955173"
}
},
"block": {
"duration": null
},
"is_block": false,
"taken_time": null,
"staff": "alireza",
"service": [
"O5KLFPZB"
]
}
'
【问题讨论】:
-
尝试打印
request.body?它的内容是什么?
标签: python angularjs json django python-3.x