views.py中的代码
from rest_framework.pagination import PageNumberPagination
from goods.models import Goods
from goods.serializers import GoodsSerializer
from rest_framework import viewsets
from rest_framework import mixins
class GoodsPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
page_query_param = "p"
max_page_size = 100
#viewsets.GenericViewSet没有get方法
class GoodsListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
"""
商品列表页
"""
queryset = Goods.objects.all()
serializer_class = GoodsSerializer
pagination_class = GoodsPagination
urls.py中的代码:
from goods.views import GoodsListViewSet
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'goods', GoodsListViewSet)
urlpatterns = [
#商品列表页
url(r'^', include(router.urls)),
]