Configure Django for production: DEBUG off, static files, PostgreSQL, and deploy to Railway with environment variables.
import os
DEBUG = os.environ.get('DEBUG', 'False') == 'True'
SECRET_KEY = os.environ.get('SECRET_KEY', 'fallback-dev-key')
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost').split(',')
# Database: switch to PostgreSQL in production
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}pip install whitenoise dj-database-url gunicorn
# settings.py
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
# ... existing middleware
]
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICSFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'web: gunicorn mysite.wsgi --log-file -# railway.app → New Project → Deploy from GitHub
# Add environment variables:
# SECRET_KEY, DATABASE_URL (Railway provisions Postgres),
# ALLOWED_HOSTS=your-app.railway.app,DEBUG=False
# Post-deploy: run migrations
railway run python manage.py migrate
railway run python manage.py collectstatic --noinputDEBUG=True in production. It exposes your full stack trace and settings to anyone who triggers an error. Set it to False and configure ALLOWED_HOSTS properly.DEBUG=False in production — no exceptions. Use env vars for secrets and settings.dj_database_url.config() parses a DATABASE_URL env var into Django's database dict.manage.py runserver which is dev-only.