DEV Community

Cover image for Django + Heroku : Guide Complet de Déploiement 2025 🚀
Fabrice
Fabrice

Posted on

1

Django + Heroku : Guide Complet de Déploiement 2025 🚀

Déployer une application Django sur Heroku peut sembler intimidant au premier abord. Dans ce guide complet, je vais vous montrer pas à pas comment déployer votre application Django et configurer votre base de données PostgreSQL sur Heroku.

🎯 Prérequis

Avant de commencer, assurez-vous d'avoir :

  • Python 3.x installĂ©
  • Git installĂ©
  • Un compte Heroku
  • Une application Django fonctionnelle en local
  • Heroku CLI installĂ©

📦 Préparation du Projet

1. Structure du Projet

Votre projet devrait ressembler Ă  ceci :

my_project/
├── manage.py
├── my_project/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt
└── Procfile
Enter fullscreen mode Exit fullscreen mode

2. Configuration des Dépendances

Créez votre requirements.txt :

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

Ajoutez ces dépendances essentielles :

django
gunicorn
psycopg2-binary
django-environ
whitenoise
dj-database-url
Enter fullscreen mode Exit fullscreen mode

3. Configuration de Django pour Heroku

Modifiez votre settings.py :

import os
import dj_database_url
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'votre-clé-secrète-par-défaut')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', 'True') == 'True'

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '').split(',')

# Database
DATABASES = {
    'default': dj_database_url.config(
        default=os.environ.get('DATABASE_URL', 'sqlite:///db.sqlite3'),
        conn_max_age=600
    )
}

# Static files
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Middleware
MIDDLEWARE = [
    # ...
    'whitenoise.middleware.WhiteNoiseMiddleware',
]
Enter fullscreen mode Exit fullscreen mode

4. Création du Procfile

Créez un fichier Procfile à la racine avec contenue :

web: gunicorn my_project.wsgi
Enter fullscreen mode Exit fullscreen mode

🚀 Déploiement sur Heroku

1. Création de l'Application

heroku create mon-app-django
Enter fullscreen mode Exit fullscreen mode

2. Configuration des Variables d'Environnement

heroku config:set SECRET_KEY='votre-clé-secrète'
heroku config:set DEBUG='False'
heroku config:set ALLOWED_HOSTS='.herokuapp.com'
Enter fullscreen mode Exit fullscreen mode

3. Base de Données PostgreSQL

heroku addons:create heroku-postgresql:hobby-dev
Enter fullscreen mode Exit fullscreen mode

4. Déploiement

git add .
git commit -m "Prêt pour le déploiement"
git push heroku main
Enter fullscreen mode Exit fullscreen mode

📺 Vidéo Tutorial
Pour une démonstration en direct de ce processus, consultez ma vidéo YouTube :


🤝 Contribution
N'hésitez pas à contribuer à ce guide en ouvrant une PR sur Developpeurtaf.
đź’¬ Discussion
Avez-vous des questions ? Des suggestions ? Laissez un commentaire ci-dessous !

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Jetbrains Survey

Calling all developers!

Participate in the Developer Ecosystem Survey 2025 and get the chance to win a MacBook Pro, an iPhone 16, or other exciting prizes. Contribute to our research on the development landscape.

Take the survey

đź‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay