Kritim Yantra
Mar 07, 2025
Django is a powerful, high-level web framework built with Python that makes it easy to create web applications quickly and efficiently. It’s designed to handle the tough parts of web development—like security, database management, and URL routing—so you can focus on building your app. Best of all, Django is free, open-source, and supported by a large community of developers.
One of the coolest things about Django is its ecosystem of packages. These are add-ons that you can plug into your project to add new features without writing everything from scratch. In this blog, we’ll dive into the top 10 Django packages that every developer should consider using. For each package, we explain what it does, how to set it up, and provide a simple, real-world code example—all in easy-to-understand terms.
Here’s the lineup of packages we’ll cover:
Let’s explore each one!
What It Does: If you want your app to talk to a mobile app or a frontend (like React), you need an API. Django REST framework makes it super simple to create these APIs by turning your data into a format (like JSON) that other apps can use.
Installation:
pip install djangorestframework
Setup: Open your settings.py
file and add 'rest_framework'
to the INSTALLED_APPS
list.
Code Example: Imagine you’re building a library app with a Book
model.
# models.py
from django.db import models
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=100)
# serializers.py
from rest_framework import serializers
from .models import Book
class BookSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = ['id', 'title', 'author']
# views.py
from rest_framework import viewsets
from .models import Book
from .serializers import BookSerializer
class BookViewSet(viewsets.ModelViewSet):
queryset = Book.objects.all()
serializer_class = BookSerializer
# urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import BookViewSet
router = DefaultRouter()
router.register(r'books', BookViewSet)
urlpatterns = [
path('', include(router.urls)),
]
Now, visit /books/
in your browser to see, add, or edit books through the API!
What It Does: Handles everything about user accounts—login, signup, password resets, and even social logins (like Google or Facebook).
Installation:
pip install django-allauth
Setup: Add the following apps to INSTALLED_APPS
in your settings.py
:
INSTALLED_APPS = [
...
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
# And add providers like:
'allauth.socialaccount.providers.google',
]
SITE_ID = 1
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
URLs: In urls.py
, add:
from django.urls import path, include
urlpatterns = [
path('accounts/', include('allauth.urls')),
]
After setup, you get ready-made pages like /accounts/login/
and /accounts/signup/
.
What It Does: Helps you filter data (e.g., showing only books by a certain author) and is great for APIs or search features.
Installation:
pip install django-filter
Setup: Add 'django_filters'
to INSTALLED_APPS
in settings.py
.
Code Example: Using our Book
model, create a filter:
# filters.py
import django_filters
from .models import Book
class BookFilter(django_filters.FilterSet):
class Meta:
model = Book
fields = ['title', 'author']
Use it in a view with Django REST framework:
# views.py
from rest_framework import generics
from .models import Book
from .serializers import BookSerializer
from .filters import BookFilter
class BookList(generics.ListAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializer
filterset_class = BookFilter
Now, you can filter books with URLs like /books/?author=John
.
What It Does: Makes forms look great with minimal effort (e.g., styled with Bootstrap).
Installation:
pip install django-crispy-forms
Setup: Add 'crispy_forms'
to INSTALLED_APPS
and set the template pack in settings.py
:
CRISPY_TEMPLATE_PACK = 'bootstrap4'
Code Example: Create a form for adding books:
# forms.py
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from django import forms
from .models import Book
class BookForm(forms.ModelForm):
class Meta:
model = Book
fields = ['title', 'author']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.add_input(Submit('submit', 'Save'))
In your template:
<!-- template.html -->
{% load crispy_forms_tags %}
{% csrf_token %}
{{ form|crispy }}
What It Does: Provides a developer toolbar that shows SQL queries, cache usage, and other debugging information.
Installation:
pip install django-debug-toolbar
Setup: Add 'debug_toolbar'
to INSTALLED_APPS
, and add its middleware in MIDDLEWARE
:
MIDDLEWARE = [
...
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INTERNAL_IPS = ['127.0.0.1']
Include the toolbar’s URLs when DEBUG=True
:
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
Once set up, a toolbar appears on your pages to help you debug your app.
What It Does: Allows you to run time-consuming tasks (like sending emails or processing files) in the background.
Installation:
pip install celery
Setup: Create a celery.py
file in your project folder:
# celery.py
from celery import Celery
app = Celery('myproject')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
In your settings.py
, set the broker URL (e.g., using Redis):
CELERY_BROKER_URL = 'redis://localhost:6379/0'
Code Example: Define a task in tasks.py
:
# tasks.py
from celery import shared_task
@shared_task
def add(x, y):
return x + y
# Run the task with:
add.delay(4, 6)
What It Does: Helps manage environment variables, keeping sensitive settings secure and easily changeable between development and production.
Installation:
pip install django-environ
Setup: In your settings.py
:
import environ
env = environ.Env()
environ.Env.read_env()
SECRET_KEY = env('SECRET_KEY')
DEBUG = env.bool('DEBUG', default=False)
Create a .env
file with your environment variables.
What It Does: Enables Cross-Origin Resource Sharing (CORS), allowing your API to work with frontends running on different domains.
Installation:
pip install django-cors-headers
Setup: Add 'corsheaders'
to INSTALLED_APPS
and add its middleware:
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
]
CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
]
What It Does: Makes it easy to import and export data (for example, managing book data from the admin panel).
Installation:
pip install django-import-export
Setup: Add 'import_export'
to INSTALLED_APPS
.
Code Example: In your admin.py
:
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from django.contrib import admin
from .models import Book
class BookResource(resources.ModelResource):
class Meta:
model = Book
class BookAdmin(ImportExportModelAdmin):
resource_class = BookResource
admin.site.register(Book, BookAdmin)
What It Does: Speeds up your application by using Redis for caching instead of hitting the database for every request.
Installation:
pip install django-redis
Setup: In settings.py
:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
}
These 10 packages can supercharge your Django projects, saving you time and effort while adding powerful features. Whether you’re building a blog, a store, or a library app, these packages cover common needs—like APIs, user authentication, data filtering, and performance improvements.
Try them out, check their official documentation for more details, and watch your development process become smoother and faster.
Happy coding!
No comments yet. Be the first to comment!
Please log in to post a comment:
Continue with Google