Featured Article

Django Rest Framework Tutorial For Beginners Geeksforgeeks Full Guide

Kenneth Jul 13, 2026

Django Rest Framework (DRF) is a powerful and flexible toolkit for creating Web APIs with the Python programming language. If you're looking to build robust APIs with Django, DRF is a must-learn library. In this Django Rest Framework tutorial, we'll navigate through essential concepts and guide you from setting up to creating APIs, serializers, and viewsets.

Django REST Framework Tutorial - Easy Steps to Install DRF & Build API in Django
Django REST Framework Tutorial - Easy Steps to Install DRF & Build API in Django

First, ensure you have Django and Django Rest Framework installed. If not, install them using pip:

Django vs Flask: Which Python Framework Should You Learn First?
Django vs Flask: Which Python Framework Should You Learn First?

```bash pip install django djangorestframework ```

Setting Up Django Rest Framework

Once installed, start by configuring your Django project to use DRF. In your main `settings.py` file, add 'rest_framework' to your `INSTALLED_APPS` and include 'rest_framework.urls' in your `urlpatterns`.

Django REST Framework Course – Build Web APIs with Python
Django REST Framework Course – Build Web APIs with Python

Next, create a new Django app. We'll call it 'rest_api'. Run the following command in your terminal:

```bash python manage.py startapp rest_api ```

Creating Models

Basic CRUD Structure in Django
Basic CRUD Structure in Django

Let's create a simple 'Book' model for this tutorial. In your 'rest_api/models.py' file:

```python from django.db import models class Book(models.Model): title = models.CharField(max_length=200) author = models.CharField(max_length=100) publication_date = models.DateField() ```

Integrate this model into your Django admin interface and run migrations. Here's how:

```bash python manage.py makemigrations python manage.py migrate ```

Inserting Data into the Database

DJANGO VS FLASK (2026)
DJANGO VS FLASK (2026)

Now that you've created a 'Book' model, add some data to it. In your Django shell:

```bash python manage.py shell ```

Then, insert data:

```python from rest_api.models import Book Book.objects.create(title='The Catcher in the Rye', author='J.D. Salinger', publication_date='1951-07-16') Book.objects.create(title='To Kill a Mockingbird', author='Harper Lee', publication_date='1960-07-11') ```

Creating Serializers

Django Tutorial - GeeksforGeeks
Django Tutorial - GeeksforGeeks

Serializers in DRF handle the conversion of your complex data types, like the 'Book' model, intoPython data types which can then be rendered into JSON, XML, etc.

Let's create a 'BookSerializer' class that serializes our 'Book' model. In your 'rest_api/serializers.py' file:

How to Build Django Rest API ? | Django Rest Framework Tutorial
How to Build Django Rest API ? | Django Rest Framework Tutorial
Django is a high-level Python framework that automates much of web development by providing tools for database management, URL routing, templates, and security. It helps developers build scalable and secure applications quickly.  💡https://www.pybeginners.com  #Python #DjangoFramework #WebApps Django Python, Django Framework, Programming Humor, Basic Computer Programming, Learn Computer Coding, Computer Coding, Coding Languages, Weird Science, Web Design Tips
Django is a high-level Python framework that automates much of web development by providing tools for database management, URL routing, templates, and security. It helps developers build scalable and secure applications quickly. 💡https://www.pybeginners.com #Python #DjangoFramework #WebApps Django Python, Django Framework, Programming Humor, Basic Computer Programming, Learn Computer Coding, Computer Coding, Coding Languages, Weird Science, Web Design Tips
DJANGO VS FASTAPI (2026)
DJANGO VS FASTAPI (2026)
a flow diagram with different types of data and information in it, including the text
a flow diagram with different types of data and information in it, including the text
Decide serializer class dynamically based on viewset actions in Django Rest Framework (DRF)
Decide serializer class dynamically based on viewset actions in Django Rest Framework (DRF)
Django Production Settings – Part I
Django Production Settings – Part I
Django ORM Cookbook — Django ORM Cookbook 2.0 documentation
Django ORM Cookbook — Django ORM Cookbook 2.0 documentation
🚀 Introduction to Web Frameworks & Django
🚀 Introduction to Web Frameworks & Django
the differences between django and flask are shown in this info graphic, which shows how
the differences between django and flask are shown in this info graphic, which shows how

```python from rest_framework import serializers from .models import Book class BookSerializer(serializers.ModelSerializer): class Meta: model = Book fields = ['id', 'title', 'author', 'publication_date'] ```

Creating APIViews

DRF provides various view classes like `ListAPIView` and `RetrieveAPIView` which handle all the routing and other HTTP methods for you. Here's how to create an `APIView` for our 'Book' model:

```python from rest_framework import generics from .models import Book from .serializers import BookSerializer class BookList(generics.ListAPIView): queryset = Book.objects.all() serializer_class = BookSerializer ```

Register this view in your 'rest_api/urls.py' file:

```python from django.urls import path from .views import BookList urlpatterns = [ path('books/', BookList.as_view(), name='books'), ] ```

Testing the API

Finally, run your Django development server:

``` python manage.py runserver ```

Navigate to `http://127.0.0.1:8000/books/` in your web browser or try it with your favorite API client. You should see a list of books rendered in JSON format.

You've now successfully created a Django Rest Framework API. Encourage yourself to explore more features like `GenericAPIView`, `ModelViewSet`, and the rich set of URL routers provided by DRF. Don't forget to secure your APIs with authentication and permissions. Happy coding!