Django实现列表页-----列表页新增(三)

from rest_framework.views import APIView
import simplejson


class AddLinkJson(APIView):

    def post(self, request):
        json_data = simplejson.loads(request.body)  # 前端数据处理为json
        if not json_data:
            return JsonError("请检查前端数据是否传输到后端")
        env = json_data["env"]
        server = json_data["server"]
        area = json_data["area"]
        link_details = json_data["link"]
        data_tuple = Link.objects.create(env=env, server=server, area=area, link_details=link_details)
        new_data = {  # 提供前端需要的数据
            ‘env‘: env,
            ‘server‘: server,
            ‘area‘: area,
            ‘link_details‘: link_details,
        }
        print(new_data)
        return JsonResponse(new_data)