当尝试将json文件输出到我的api时,我收到以下错误 -
{
"detail": "Not found"
}
这仅在我尝试将新项目更新为现有项目时才有效。这是我的观点 -
class DeployEventView(APIView):
def get_object(self, pk):
try:
return Trgmst.objects.get(pk=pk)
except Trgmst.DoesNotExist:
raise Http404
def get(self, request, format=None):
name = self.request.GET.get('name')
pk = Trgmst.objects.filter(trgmst_name=name).values_list('trgmst_id', flat=True)
trgmst = self.get_object(pk)
serializer = EventSerializer(trgmst)
return Response(serializer.data)
def put(self, request, format=None):
name = self.request.GET.get('name')
pk = Trgmst.objects.filter(trgmst_name=name).values_list('trgmst_id', flat=True)
trgmst = self.get_object(pk)
serializer = EventSerializer(trgmst, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, format=None):
name = self.request.GET.get('name')
pk = Trgmst.objects.filter(trgmst_name=name).values_list('trgmst_id', flat=True)
trgmst = self.get_object(pk)
trgmst.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
这是我试图投入的网址 -
http://localhost:9001/deploy/event/
我也试过这个网址 - (项目目前不存在)
http://localhost:9001/deploy/event/?name=evnt_job_test
这是我的json -
{
"trgmst_id": 2249,
"trgmst_type": 1,
"trgmst_name": "evnt_job_TEST ",
"trgmst_desc": null,
"trgmst_public": "Y",
"trgmst_active": "Y",
"trgmst_trigger": 10,
"owner_name": "Operations ",
"trgmst_jobctl": 1,
"trgmst_alljobs": "N",
"trgmst_lstchgtm": "2014-09-26T13:44:27",
"trgmst_parm": "OP=0,EX1=1,EX2=1",
"trgmst_maxreruns": 0,
"nodmst_name": null,
"servicemst_name": null,
"trgmst_info": null,
"trgmst_monitor": 1,
"trgmst_trgtskcnt": 0,
"trgmst_lasttrgtskrun": null,
"event_action_details": [
{
"trgtsk_id": 2982,
"trgmst_id": 2249,
"tskmst_id": null,
"trgtsk_order": 1,
"trgtsk_type": 1
}
]
}
答案 0 :(得分:0)
您可能会将JSON发送到可浏览的API,该API需要表单,而不是JSON数据。
尝试将数据发送到以下网址:
http://localhost:9001/deploy/event/?format=json