【发布时间】:2019-12-31 08:41:44
【问题描述】:
我想从请求中单独检索时间字段。但是当我尝试处理值时,HttpResponse 会给出 406 状态码。
def ReservationActions(request):
if(request.method == 'POST'):
body_as_json = json.loads(request.body)
try:
veh = Vehicles.objects.get(id = body_as_json['vehic__id'])
sp = ParkingSpots.objects.get(id = body_as_json['spot__id'])
reserve = Reservations(vehic = veh, spot = sp, start_date = body_as_json.get('start'), end_date = body_as_json.get('end'))
if(reserve.start_date.datetime.minute % 15 is not 0): #this is where it goes to "except" part
return HttpResponse(status=306)
reserve.save()
# Return a "created" (201) status code.
return HttpResponse(status=201)
except:
# Return a "not acceptable" (406) status code.
return HttpResponse(status=406)
这是我发送的 json 对象:
{
"vehic__id": 1,
"spot__id": 1,
"start": "2018-03-29T23:00:00.999Z",
"end" : "2018-03-30T23:00:30.000Z"
}
【问题讨论】:
标签: json datetime django-models request tastypie