Skip to content
Django
5. Django Modules

Installation of Third Party Modules

1. WhiteNoise

WhiteNoise allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3 or any other external service.

Install WhiteNoise

Terminal
pip install whitenoise

Add WhiteNoise Middleware

Add the WhiteNoise middleware to the MIDDLEWARE list in the settings.py file.

settings.py
MIDDLEWARE = [
    # ...
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

Add WhiteNoise Storage

Add the WhiteNoise storage to the STATICFILES_STORAGE in the settings.py file.

settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

Add WhiteNoise Configuration

Add the WhiteNoise configuration to the wsgi.py file.

wsgi.py
from django.core.wsgi import get_wsgi_application
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PROJECT_NAME.settings')
 
application = get_wsgi_application()
 
from whitenoise import WhiteNoise
 
application = WhiteNoise(application)

2. Collect Static Files

Collect all static files in one folder. It is used when you deploy your project.

Collect Static Files

Terminal
python manage.py collectstatic

Add Static & Media Files

Add the static and media files in the urls.py file.

urls.py
from django.conf import settings
from django.conf.urls.static import static
 
urlpatterns = [
    # your paths are here ...
]
 
# or
 
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

3. Django Cors Headers

Django CORS (Cross-Origin Resource Sharing) headers is used to allow requests from other domains. It is used when you want to access your API from another domain.

Install Django Cors Headers

Terminal
pip install django-cors-headers

Add Cors Headers Middleware

Add the Cors Headers middleware to the MIDDLEWARE list in the settings.py file.

settings.py
MIDDLEWARE = [
    # ...
    'corsheaders.middleware.CorsMiddleware',
]

Add Cors Headers Configuration

Add the Cors Headers configuration to the settings.py file.

settings.py
CORS_ALLOWED_ORIGINS = [
    "http://localhost:3000",
    "http://localhost:8000",
]

4. Django Rest Framework

Django REST framework is a powerful and flexible toolkit for building Web APIs. It is used when you want to create REST API.

Terminal
pip install djangorestframework

5. Django Widget Tweaks

Django Widget Tweaks is a small app that lets you add classes and HTML attributes to forms widgets.

Terminal
pip install django-widget-tweaks

6. Django Crispy Forms

Django Crispy Forms is a Django application that lets you easily build, customize and reuse forms using your favorite CSS framework.

Terminal
pip install django-crispy-forms

7. Django Filter

Django-filter is a generic, reusable application to alleviate writing some of the more mundane bits of view code.

Terminal
pip install django-filter

8. Django Rest Framework Simple JWT

Simple JWT provides a JSON Web Token authentication backend for the Django REST Framework.

Terminal
pip install djangorestframework_simplejwt