标签:lookup list 渲染 字典 建立 update serial mod ret
不懂使用机制的直接看源码就好了,也不是很难,能够看得懂
from django.views import View
from rest_framework.views import View
from rest_framework.generics import GenericAPIView
from rest_framework import mixins
from rest_framework.mixins import CreateModelMixin,UpdateModelMixin,RetrieveModelMixin,ListModelMixin,DestroyModelMixin
from rest_framework import generics
视图集,继承了mixins所有的类 和 GenericAPIView所有的方法
使用:
#在view.py中
from rest_framework.viewsets import ModelViewSet
class CarAPIView(ModelViewSet):
queryset = models.car.objects.all()
serializer_class = Serializers.CarSerializer
#在urls.py中(这里的car只是用来做例子)
urlpatterns = [
#以什么方式请求,就要在字典中,写上请求方式和请求的函数
url(r'^car/$',views.CarAPIView.as_view({'get':'list','post':'create'})),
url(r'^car/(?P<pk>\d+)',views.CarAPIView.as_view({'get':'retrieve','put':'update','patch':'partial_update'}))
]
标签:lookup list 渲染 字典 建立 update serial mod ret
原文地址:https://www.cnblogs.com/kuck/p/11921941.html