django drf viewsets和routers
阿新 • • 發佈:2019-04-04
rtc generic eric obj clas 圖片 models rest 分享
1.定義VIew
from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status from rest_framework.parsers import JSONParser from rest_framework import mixins, generics from rest_framework.generics importListAPIView from rest_framework.pagination import PageNumberPagination from goods.models import Goods, GoodsCategory from goods.serializer import GoodsSerializer, CategorySerializer from rest_framework import viewsets class GoodsList(mixins.ListModelMixin, viewsets.GenericViewSet): classGoodsPagination(PageNumberPagination): page_size = 2 page_size_query_param = ‘pageSize‘ page_query_param = ‘p‘ max_page_size = 100 queryset = Goods.objects.all()[:10] serializer_class = GoodsSerializer pagination_class = GoodsPagination
2.兩種方式配置url
django drf viewsets和routers