Featured Article

Django Rest Framework Tutorial PDF: Master API Development in Easy Steps

Kenneth Jul 13, 2026

Are you a Python developer eager to delve into building robust APIs? Look no further than Django Rest Framework (DRF), a powerful and flexible toolkit for building web APIs. If you're ready to start your DRF journey, you're in the right place. In this comprehensive tutorial, we'll guide you through the essential aspects of Django Rest Framework, from installation to creating and testing APIs. Let's get started with our easy-to-follow DRF tutorial, available both online and as a PDF download.

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

Before we dive into the world of DRF, let's ensure you have the prerequisites. You should have a basic understanding of Django, Python, and the command line. If you're not familiar with Django, don't worry – we'll provide links to helpful resources throughout the tutorial. Now, let's install DRF and set up a new Django project.

the diagram shows how to use django
the diagram shows how to use django

Setting up Django Rest Framework

To begin, we'll install DRF using pip and create a new Django project if you haven't already. We'll also generate a new Django app within our project where we'll build our APIs.

Why Django Framework is Best For Web Development?
Why Django Framework is Best For Web Development?

If you haven't installed pipenv, a package installer for Python, you can do so with this command:

pip install pipenv

Django Project Structure Explained (Beginner Guide)
Django Project Structure Explained (Beginner Guide)

Now, you can use pipenv to install Django and DRF in a new project. Let's create a new project called 'myproject' and navigate to its directory:

pipenv --python=3.8

pipenv install django djangorestframework

Create Views in Django
Create Views in Django

pipenv shell

django-admin startproject myproject

cd myproject

Django ORM Cookbook — Django ORM Cookbook 2.0 documentation
Django ORM Cookbook — Django ORM Cookbook 2.0 documentation

python manage.py startapp myapp

Including DRF in your Django project

a diagram with the words django in different languages
a diagram with the words django in different languages
| Pythonista Planet
| Pythonista Planet
Start a Django Project
Start a Django Project
Django Rest Framework
Django Rest Framework
🔗 Django Models: OneToOneField (One-to-One Relationship)
🔗 Django Models: OneToOneField (One-to-One Relationship)
Basic CRUD Structure in Django
Basic CRUD Structure in Django
Django Deployment Simplified
Django Deployment Simplified
Django: MVT(Model-View-Template)
Django: MVT(Model-View-Template)
How to Build Django Rest API ? | Django Rest Framework Tutorial
How to Build Django Rest API ? | Django Rest Framework Tutorial

Once DRF is installed, add 'rest_framework' and 'myapp' to your INSTALLED_APPS in the settings.py file of your project.

INSTALLED_APPS = [ # ... 'rest_framework', 'myapp' ]

Next, let's configure the authentication system. For this tutorial, we'll use Django's built-in authentication. Add 'rest_framework.authtoken' to your INSTALLED_APPS and adjust the authentication settings:

REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', ),}

With DRF integrated into your Django project, it's time to create our first API.

Creating your first API with Django Rest Framework

Let's create a simple model and serializer to start making API endpoints. First, define a model in models.py of your app:

from django.db import models

class Item(models.Model):

name = models.CharField(max_length=100)

value = models.DecimalField(max_digits=10, decimal_places=2)

Then, create a serializer for this model in a new file called serializers.py:

from rest_framework import serializers

from .models import Item

class ItemSerializer(serializers.ModelSerializer):

class Meta:

model = Item

fields = ('id', 'name', 'value')

Now that we have a serializer, let's create views for listing and creating items. Add the following code to a new file called views.py:

from rest_framework import viewsets

from .models import Item

from .serializers import ItemSerializer

class ItemViewSet(viewsets.ModelViewSet):

queryset = Item.objects.all()

serializer_class = ItemSerializer

Next, we need to include our new API views in the project's urlpatterns. Open the urls.py file of your project and add the following import and line:

from django.urls import path, include

from rest_framework_nested import routers

Then, set up the URL routes:

router = routers.DefaultRouter()

router.register('items', ItemViewSet)

urlpatterns = [ # ... path('api/', include(router.urls)), ]

Testing your Django Rest Framework API

Before running your development server, let's test our API using curl. First, create a superuser to authenticate with our API:

python manage.py createsuperuser

Next, obtain a token for this user with this command:

python manage.py shell

from django.contrib.auth.models import User

user = User.objects.get(username='your_username')

from rest_framework.authtoken.models import Token

token = Token.objects.create(user=user)

print(token.key)

Finally, make a GET request to our API (replace 'your_token' with your actual token):

curl -H "Authorization: Token your_token" http://localhost:8000/api/items/

Congratulations! You've just created and tested your first API using Django Rest Framework.

Exploring more Django Rest Framework features

Now that you have a solid foundation, it's time to dive deeper into DRF. In the next sections of our tutorial, we'll explore more advanced topics such as:

  • Serializers: Validating and serializing data
  • Views and Routers: Organizing and configuring your APIs
  • Authentication and Permissions: Securing your APIs
  • Throttling and Pagination: Handling API requests efficiently
  • Relationships: Handling related models and API endpoints

Ready to take your API skills to the next level? Download our comprehensive DRF tutorial PDF and start exploring these exciting topics today!

As you delve into the world of Django Rest Framework, remember that practice makes perfect. Don't be afraid to experiment and make mistakes – it's the best way to learn. Happy coding, and we can't wait to see the incredible APIs you'll build!