Course Content
Django REST Framework
Django REST Framework
Additional Information: Built-in Views
In Django REST Framework, built-in views are like tools that help create parts of an API. They allow your web application to receive requests from users and send them responses. For example, when you visit a webpage or use a mobile app and click buttons, those actions generate requests. Built-in views in DRF help process these requests and send responses back to users.
During the course, we will be using ModelViewSet, but it's worth knowing about its alternatives.
-
APIView: This is the base class for creating your own views. You can define the logic for handling HTTP requests (GET, POST, PUT, DELETE, etc.) in methods of the class such as
get()
,post()
,put()
,delete()
; -
GenericAPIView: This class provides additional conveniences for working with Django models, including support for CRUD operations (create, read, update, delete). It combines the functionality of
APIView
with features that facilitate working with models, such as serializers, querysets, etc; -
ViewSet: This class provides a way to organize views for different types of requests at the resource level. For example, you can have methods for handling GET, POST, PUT, DELETE requests for a single resource (e.g.,
/api/users/
). ViewSet simplifies code organization, as you can describe all related methods for one resource in one class; -
ReadOnlyModelViewSet: This is a subclass of
ModelViewSet
that allows only reading data. It automatically generates methods for handling GET requests but does not allow modifying data.
By using these built-in views, you can quickly create an API with minimal code. DRF also provides many options for customizing and extending these built-in views, allowing you to create complex APIs according to your needs.
Thanks for your feedback!