Prerequisites
- A working Django project
- Heroku CLI installed
- Git initialized in your project
Step 1 — Install Required Packages
pip install gunicorn whitenoise psycopg2-binary django-environ
Step 2 — Create Procfile
Create a file named Procfile (no extension) in your root directory:
web: gunicorn config.wsgi --log-file -
Step 3 — Configure WhiteNoise
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
# ... other middleware
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Step 4 — Deploy
heroku create your-app-name
heroku addons:create heroku-postgresql:mini
heroku config:set SECRET_KEY="your-secret" DEBUG=False
git push heroku main
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
Conclusion
Your Django app is now live! Heroku handles SSL, scaling, and server management automatically.