0–5 min
Real Hook
5–25 min
Core Concept
25–45 min
Live Coding
45–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)

Your app works on localhost. But localhost is invisible to the world. Deploying means your app runs 24/7 on a server in the cloud, reachable by anyone on the planet.

Railway deploys Python apps in 5 minutes from a GitHub repo. No Docker, no Kubernetes, no AWS configuration. The same platform used by thousands of Indian startups to get their Python backend live the same day.

📦 3 Things a Server Needs (5–25 min)

💡 Pre-deployment Checklist

requirements.txt — Railway reads this to install your packages. Run pip freeze > requirements.txt
Procfile — tells Railway how to start your app: web: gunicorn myproject.wsgi
Environment Variables — SECRET_KEY, DATABASE_URL, DEBUG=False. Never commit secrets.

💻 Live Demo — Deploy in 5 Steps (25–45 min)

# Step 1: Production-ready settings
pip install gunicorn dj-database-url django-environ whitenoise

# settings.py changes for production
import environ
env = environ.Env()
environ.Env.read_env()

DEBUG      = env.bool("DEBUG", default=False)
SECRET_KEY = env("SECRET_KEY")
ALLOWED_HOSTS = [".railway.app", "127.0.0.1"]

# Static files (whitenoise serves CSS/JS without a CDN)
MIDDLEWARE = [... "whitenoise.middleware.WhiteNoiseMiddleware" ...]
STATIC_ROOT = BASE_DIR / "staticfiles"

# Database from environment variable
DATABASES = {
    "default": env.db()           # reads DATABASE_URL env var
}
# Step 2: Procfile (no extension) at project root
web: gunicorn myproject.wsgi --log-file -

# Step 3: runtime.txt (tell Railway which Python version)
python-3.12.0

# Step 4: Collect static files
python manage.py collectstatic --no-input

# Step 5: Push to GitHub, then Railway
git add .
git commit -m "deploy: production settings"
git push origin main

# Railway: connect GitHub repo → New Service → Add env vars:
# SECRET_KEY=your-long-secret-key-here
# DEBUG=False
# Railway auto-provides DATABASE_URL for PostgreSQL
📉 After Deploy

Run migrations on production: in Railway dashboard, open Shell tab and run python manage.py migrate. Then python manage.py createsuperuser. Now your app is live, has a database, and has an admin user.

🎯 You Code It (45–55 min)
  1. Update your Django project: install gunicorn, whitenoise, django-environ
  2. Create Procfile and runtime.txt in project root
  3. Update settings.py for production (DEBUG=False, SECRET_KEY from env, whitenoise)
  4. Run pip freeze > requirements.txt
  5. Push to GitHub, create Railway account, connect repo
  6. Add environment variables in Railway dashboard, deploy
  7. Show: Your app running on a .railway.app URL — share the link

📄 Day 13 Cheat Sheet — Django Deployment

Key Files

requirements.txtpip freeze > requirements.txt
Procfileweb: gunicorn app.wsgi
runtime.txtpython-3.12.0
.envLocal env vars (never commit)
.gitignoreAdd .env, __pycache__, venv

Production Settings

DEBUG = FalseNever True in prod
ALLOWED_HOSTS = [domain]Whitelist your domain
SECRET_KEY from envNever hardcode
collectstaticBundle static files
HTTPS onlyRailway handles SSL

Railway Commands

railway loginAuthenticate CLI
railway initLink project
railway upDeploy current code
railway run python manage.py migrateRun on prod
railway logsLive logs

Environment Variables

SECRET_KEYDjango secret key
DEBUGFalse
DATABASE_URLAuto from Railway PostgreSQL
ALLOWED_HOSTS.railway.app
CORS_ALLOWED_ORIGINSYour frontend URL