Django REST
About Lesson

In this Django REST Framework lesson we are going to learn about Django REST Framework Mixins, one of the key benefits of class-based views is the way they allow you to compose bits of reusable behavior. REST framework takes advantage of this by providing a number of pre-built views that provide for commonly used patterns. the generic views provided by REST framework allow you to quickly build API views that map closely to your database models. if the generic views don’t suit the needs of your API, you can drop down to using the regular APIView class, or reuse the mixins and base classes used by the generic views to compose your own set of reusable generic views.

 

 

 

OK now we are changing our views.py file, and we are removing the previous codes, by using this code you can add, get, update and delete the data. also there are separate mixins for different functionalities, for example posting article we are going to use CreateModelMixin, for getting the articles we are using ListModelMixin, for updating we are using UpdateModelMixin and for deleting we can use DestroyModelMixin.

 

 

 

This is our urls.py file.

 

 

 

If you go to http://localhost:8000/articles/  you can see a browsable api from the django rest framework with same functionality of posting article, getting article, retrieving article, deleting article and updating article, but this time we have used generic view and mixins.

Django REST Framework Mixins
Django REST Framework Mixins

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found