基本路由寫法:post
url(r'^publish/', views.PublishView.as_view()),
1
第二種寫法(只要繼承了ViewSetMixin):url
url(r'^publish/$', views.PublishView.as_view({'get':'list','post':'create'})),
url(r'^publish\.(?P<format>\w+)$', views.PublishView.as_view({'get':'list','post':'create'})),
url(r'^publish/(?P<pk>\d+)$', views.PublishView.as_view({'get':'retrieve','delete':'destroy','put':'update'})),
1
2
3
第三種(自動生成路由,必須繼承ModelViewSet):
SimpleRouter 自動生成兩條路由:rest
from rest_framework.routers import SimpleRouter,DefaultRouter
router=SimpleRouter()
router.register('publish',views.PublishView)
、、、、
url(r'', include(router.urls)),
1
2
3
4
5
DefaultRouter自動生成四條路由:orm
from rest_framework.routers import SimpleRouter,DefaultRouter
router=DefaultRouter(http://www.my516.com/heimitao/)router
router.register('publish',views.PublishView)
、、、、
url(r'', include(router.urls)),
--------------------- 繼承