其他分享
首页 > 其他分享> > DRF-类视图(GenericAPIView)

DRF-类视图(GenericAPIView)

作者:互联网

from rest_framework.views import APIView
from meituan.models import Merchant
from django.http import Http404
from .serializers import MerchantSerializer
from rest_framework.response import Response
from rest_framework import status
from rest_framework import generics

class MerchantView(
    generics.CreateAPIView,
    generics.UpdateAPIView,
    generics.DestroyAPIView,
    generics.RetrieveAPIView
):
    queryset = Merchant.objects.all()
    serializer_class = MerchantSerializer
    # lookup_field = 'name'

class MerthantListView(
    generics.ListAPIView
):
    queryset = Merchant.objects.all()
    serializer_class = MerchantSerializer

标签:GenericAPIView,self,queryset,视图,rest,generics,import,serializer,DRF
来源: https://www.cnblogs.com/xshan/p/14220326.html