1. Prerequisites 📝
Python 3.7 andpip on your machineGit for version control- A free account on Heroku
Django project folder initialized locallyVirtualenv orvenv to isolate dependencies
2. Create Heroku Account and Install CLI ⚙️
- Download installer for your OS from the official site
- Run
heroku login in your terminal and follow prompts
3. Prepare Your Django Project 🔧
3.1 Update settings.py
• Use
• Configure
3.2 requirements.txt, runtime.txt, Procfile
| File | Purpose | Example |
|---|---|---|
| List dependencies |
Django==4.1.0 gunicorn==20.1.0 dj-database-url==0.5.0 whitenoise==6.2.0 |
|
| Specify Python version | python-3.9.13 | |
| Define process types | web: gunicorn myproject.wsgi –log-file – |
4. Initialize Git Repository and Commit 📦
- Run
git init in your project root - Create a
.gitignore (excludevenv/ ,__pycache__ ) git add . andgit commit -m Initial Django app for Heroku
5. Create Heroku App and Configure Add-ons 🛠️
• Add Heroku Postgres:
• Verify config with
6. Set Environment Variables 🔒
heroku config:set SECRET_KEY=your-production-secret heroku config:set DEBUG=False - For Django-Environ users, set DATABASE_URL automatically by Postgres add-on
7. Deploy to Heroku 🚀
git push heroku main (orgit push heroku master )- Heroku will install dependencies, detect Python, build slug
- Watch the output for build success ✅
8. Run Migrations and Collect Static 🗄️
heroku run python manage.py migrate to apply database migrationsheroku run python manage.py collectstatic –noinput to gather static files via WhiteNoise
9. Monitor, Scale, and Manage Logs 📊
• Scale dynos:
• Inspect Postgres:
10. Custom Domain and SSL 🌐
heroku domains:add www.yourdomain.com - Configure your DNS
CNAME to the Heroku endpoint - Heroku provides free SSL certificates automatically
Conclusion ✅
From here, explore performance monitoring, CI/CD integrations, and team collaboration features. Keep your dependencies updated, review your logs regularly, and enjoy the power of seamless cloud deployment.
For more details, visit the Heroku Dev Center and the Django documentation.