Django Lesson 10: Deployment
Deploying Django requires a few production settings. We’ll use Railway for the easiest deployment path.
Production Settings
# settings.py production changes
DEBUG = False
ALLOWED_HOSTS = ["yourdomain.com", "yourapp.railway.app"]
SECRET_KEY = os.environ["SECRET_KEY"] # from env var, never hardcode!
# Static files
import dj_database_url
DATABASES = {"default": dj_database_url.parse(os.environ["DATABASE_URL"])}
# pip install whitenoise
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
...
]
STATIC_ROOT = BASE_DIR / "staticfiles"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
Deploy to Railway
# requirements.txt (generate with pip freeze)
pip freeze > requirements.txt
# Add: gunicorn, whitenoise, dj-database-url, psycopg2-binary
# Procfile
web: gunicorn myblog.wsgi
# Deploy:
git push origin main
# Railway detects Django, runs migrations, starts server!
You completed the Django course!
- FastAPI — Modern async Python API framework
- Celery — Background tasks for Django
🏋️ Practice Task
Deploy your task manager to Railway. Create requirements.txt. Create Procfile. Set environment variables in Railway. Run migrations on production. Test all features live.
💡 Hint: railway login && railway init && railway up. Or: push to GitHub, connect in Railway dashboard.