1 from rest_framework.views import APIView 2 import simplejson 3 4 5 class AddLinkJson(APIView): 6 7 def post(self, request): 8 json_data = simplejson.loads(request.body) # 前端数据处理为json 9 if not json_data: 10 return JsonError("请检查前端数据是否传输到后端") 11 env = json_data["env"] 12 server = json_data["server"] 13 area = json_data["area"] 14 link_details = json_data["link"] 15 data_tuple = Link.objects.create(env=env, server=server, area=area, link_details=link_details) 16 new_data = { # 提供前端需要的数据 17 ‘env‘: env, 18 ‘server‘: server, 19 ‘area‘: area, 20 ‘link_details‘: link_details, 21 } 22 print(new_data) 23 return JsonResponse(new_data)
原文:https://www.cnblogs.com/nieliangcai/p/12844096.html