コード例 #1
0
    def get(self, request):
        response = MyResponse()
        course_list = models.Course.objects.all()
        course_ser = MySer.CourseSer(instance=course_list, many=True)
        response.msg = '查询成功'
        response.data = course_ser.data

        return Response(response.get_data)
コード例 #2
0
 def get(self, request):
     # 获取购物车接口
     response = MyResponse()
     shopping_cart_bytes = self.conn.get('shopping_cart_%s' %
                                         request.user.pk)
     shopping_cart_dic = json.loads(
         shopping_cart_bytes) if shopping_cart_bytes else {}
     response.msg = '查询购物车成功'
     response.data = shopping_cart_dic
     return Response(response.get_data)
コード例 #3
0
    def get(self, request, pk):
        response = MyResponse()
        # pk 是课程的id,查询的是课程详情表******
        try:
            course_detail = models.CourseDetail.objects.get(course_id=pk)
            coursedetailser = MySer.CourseDetailSer(instance=course_detail,
                                                    many=False)
            response.data = coursedetailser.data
        except ObjectDoesNotExist as e:
            response.msg = '该课程不存在'
            response.status = 101
        except Exception as e:
            response.msg = str(e)
            response.status = 105

        return Response(response.get_data)