![]() |
Django Rest Framework (DRF) provides powerful tools for building RESTful APIs in Django projects. One of the key components of DRF is Concrete GenericAPIViews, which offer pre-implemented views for common CRUD (Create, Read, Update, Delete) operations. In this article, we will see Concrete GenericAPIViews in Django Rest Framework. What is Concrete GenericAPIViews in Django?Concrete GenericAPIViews in Django are pre-defined view classes that simplify the creation of RESTful APIs by providing ready-to-use functionalities for common HTTP methods like GET, POST, PUT and DELETE. They include classes like Concrete GenericAPIViews in Django Rest FrameworkBelow, are the Implementation of Concrete GenericAPIViews in the Django Rest Framework in Python: Starting the Project FolderTo start the project use this command django-admin startproject bookstore To start the app use this command django-admin startapp books Now add this app to the ‘settings.py’ INSTALLED_APPS = [ For install the Django rest_framework use the below command pip install djangorestframework File Structure![]() File Structure Setting Necessary Filesbooks/models.py: Define the Book model as follows:
books/serializers.py : Create a file named serializers.py and define the Book serializer.
books/views.py : Create a file named views.py and define the views for handling CRUD operations:
books/urls.py : Define the URLs for the views using the following code:
bookstore/urls.py: Include the URLs of the books app using the following code.
Deployment of the ProjectRun these commands to apply the migrations: python3 manage.py makemigrations Run the server with the help of following command: python3 manage.py runserver Output ![]() Post Concrete GenericAPIViews in Django ![]() Get Concrete GenericAPIViews in Django Video Demonstration |
Reffered: https://www.geeksforgeeks.org
Django |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |