Routing First Class: Primitive inheritance apiview #http://127.0.0.1:8000/api/v1/auth/URL (r'^auth/$', views. Authview.as_view ()),#Http://127.0.0.1:8000/api/v1/auth.json # want the page to show JSON formatURL (r'^auth\. (? p<format>[a-z0-9]+) $', views. Authview.as_view ()),#http://127.0.0.1:8000/api/v1/auth/1/URL (r'^auth/(? p<pk>\d+)/$', views. Authview.as_view ()),#Http://127.0.0.1:8000/api/v1/auth/1.jsonURL (r'^auth/(? p<pk>\d+) \. (? p<format>[a-z0-9]+) $', views. Authview.as_view ()),classAuthview (views. Apiview):defGet (self,request,*args,**Kwargs):returnResponse ('...') Type II: Inherit modelviewset url (r'^index/$', views. Indexview.as_view ({'Get':'List','Post':'Create'}), url (r'^index/\. (? p<format>[a-z0-9]+) $', views. Indexview.as_view ({'Get':'List','Post':'Create'}), url (r'^index/(? p<pk>\d+)/$', views. Indexview.as_view ({'Get':'Retrieve','Delete':'Destroy','put':'Update','Patch':'partial_update'}), url (r'^index/(? p<pk>\d+) \. (? p<format>[a-z0-9]+) $', views. Indexview.as_view ({'Get':'Retrieve','Delete':'Destroy','put':'Update','Patch':'partial_update'})), classIndexview (viewsets. Modelviewset): Queryset=models. UserInfo.objects.all () Serializer_class=Indexserializer Pagination_class=P2 Third class: Automatically help us to generate four kinds of url,index/$,index/(? p<pk>\d+) $,index/\. (? p<format>[a-z0-9]+) $,index/(? p<pk>\d+) \. (? p<format>[a-z0-9]+)$ fromRest_framework.routersImportDefaultrouter Router=Defaultrouter () router.register ('Index', views. Indexviewset) Urlpatterns=[url (r'^', include (Router.urls)),]classIndexviewset (viewsets. Modelviewset): Queryset=models. UserInfo.objects.all () Serializer_class=Indexserializer Pagination_class=P2classIndexserializer (serializers. Modelserializer):classMeta:model=models. UserInfo Fields="__all__"
Routing of the Python-django rest Framework Framework