1 class SearchLinkJson(APIView): 2 """搜索""" 3 def post(self, request): 4 """前端提交表单后,获取表单数据, 组成一个dict,再用filter过滤""" 5 json_data = simplejson.loads(request.body) 6 id = json_data.get(‘id‘) 7 env = json_data.get(‘env‘) 8 server = json_data.get(‘server‘) 9 area = json_data.get(‘area‘) 10 link_details = json_data.get(‘link_details‘) 11 search_data = {} 12 if id: 13 search_data["id"] = id 14 if env: 15 search_data["env"] = env 16 if server: 17 search_data["server"] = server 18 if area: 19 search_data["area"] = area 20 if link_details: 21 search_data["link_details"] = link_details 22 print(search_data) 23 data = Link.objects.filter(**search_data) 24 return JsonResponse(data)
原文:https://www.cnblogs.com/nieliangcai/p/12844209.html