[1122 | Day64] drf view large family introduction and usage

drf framework | View family

1. Views | view class

The same method on the request to a view of a mapping class, in response to a request to complete

1)APIView

  • View all the features of
  • Rewrite as_view disabled csrf certification
  • Rewrite dispatch: request, response, rendering, an exception, parsing, three certification
  • A bunch of multi-class attributes may be accomplished partial view class

2) GenericAPIView

  • APIView all the features

  • Three properties:

    • queryset
    • serializer_class
    • lookup_url_kwarg
  • Three methods:

    • get_object (): Get a single (according pk)
    • get_queryset (): Gets all
    • get_serializer (* args, ** kwargs): Gets the specified number of common parameters
      • data: for parameter passing deserialization
      • many: acquiring a plurality of sequences of objects
      • instance: If you save executed, the update method; on the contrary, create a method
      • partial: True modify the local field; default False

2. mixins | View Tools

  • Five Tools
    • RetrievModelMixin
    • ListModelMixin
    • CreateModelMixin
    • UpdateModelMixin
    • DestroyModelMixin
  • Six utility methods
    • monosubstituted retrieve >>>
    • list >>> group to take
    • create >>> monocytogenes
    • Single overall change update >>>
    • Single locally modified partial_update >>>
    • Single delete destroy >>>

3. generics | view class tools

Mixins pile of tools in combination with the base class view GenericAPIView

4. Set the base view class

1)ViewSet(ViewSetMixin,APIView) : You can define mappings from APIView

2)GenericViewSet(ViewSetMixin,GenericAPIView) : You can define mappings from GenericAPIView

5. ViewSetMixin | view toolset

Rewriting as_view (), to complete the custom mapping request to a view of the method of

as_view({'get': 'my_get'})

6. The set of views used Model

1)ModelViewSet(mixins.CreateModelMixin,

mixins.RetrievModelMixin,

mixins.UpdateModelMixin,

mixins.DestroyModelMixin,

mixins.ListModelMixin,

GenericViewSet) : six operational view of a resource set

2)ReadOnlyModelViewSet(mixins.RetrievModelMixin,

mixins.ListModelMixin,

GenericViewSet) : a read-only view of the operation of a resource set

Guess you like

Origin www.cnblogs.com/fxyadela/p/11913754.html