django-rest-framework介绍

来源:互联网 发布:大乐网络代理什么游戏 编辑:程序博客网 时间:2024/05/19 02:04
# django-rest-framework介绍 
# http://www.django-rest-framework.org/


Viewset组合使用 


#继承关系  绑定urls
GenericViewSet(viewset)       -drf
GenericAPIView            -drf
APIView               -drf
View              -django



Mixin
CreateModelMixin
ListModelMixin
RetriveModelMixin
UpdateModeMixin
DestroyModelMixin




Django 两个类的使用 request; response;


访问Django-filter 如何使用


#自己序列化 使用了
通过Django的View  model_to_dict方法  serializers JsonResponse来完成序列化
 """
    商品列表页, 分页, 搜索, 过滤, 排序
    """
    # throttle_classes = (UserRateThrottle, )
    queryset = Goods.objects.all()
    serializer_class = GoodsSerializer
    pagination_class = GoodsPagination
    # authentication_classes = (TokenAuthentication, )
    filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter)
    filter_class = GoodsFilter
    search_fields = ('name', 'goods_brief', 'goods_desc')
    ordering_fields = ('sold_num', 'shop_price')