DjangoRestFramework routing configuration

There are three main ways to configure routing:
the first is the configuration method of django

path('goods/', GoodsListApi.as_view(), name="goods_list")

The second is:
the get request will convert the list request so that ListModelMixin can be used

good_list=GoodsListViewSet.as_view({
    
    
     "get":"list",

 })
urlpatterns = [
path('goods/', good_list, name="goods_list")]

The third recommended use:
need to be configured in urls

router=DefaultRouter()
router.register('goods',GoodsListViewSet,basename='goods')
urlpatterns = [
url('^', include(router.urls)),
]

Through the third method, you can see the effect when the project is running.
insert image description here

Guess you like

Origin blog.csdn.net/qq_48082548/article/details/127066378