基本路由写法:
url(r'^publish/', views.PublishView.as_view()),
1
第二种写法(只要继承了ViewSetMixin):
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 自动生成两条路由:
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自动生成四条路由:
from rest_framework.routers import SimpleRouter,DefaultRouter
router=DefaultRouter(http://www.my516.com/heimitao/)
router.register('publish',views.PublishView)
、、、、
url(r'', include(router.urls)),
---------------------