一、VueShop/urls.py
from goods.views import GoodsListViewSet from rest_framework.routers import DefaultRouter router = DefaultRouter() #配置goods的url router.register(r'goods', GoodsListViewSet) urlpatterns = [ #商品列表页 re_path('^', include(router.urls)), ]
二、views.py
class GoodsListViewSet(mixins.ListModelMixin,viewsets.GenericViewSet): '商品列表页' # 分页 pagination_class = GoodsPagination #这里必须要定义一个默认的排序,否则会报错 queryset = Goods.objects.all().order_by('id') serializer_class = GoodsSerializer