AGENT SKILL

django-production-audit

Audit a Django project for production deployment readiness — systematically check configuration, dependencies, version control, and infrastructure prerequisites before deploying to platforms like Vercel, Railway, Heroku, or any WSGI host.

License 许可
MIT
最近更新
2026-08-16
Stars
★ 0
Forks
0

01 前言 Front Matter

name
django-production-audit
tags
[ "django", "deployment", "production", "audit", "vercel", "supabase", "postgresql" ]
author
Hermes
license
MIT
version
1.0.0
platforms
[ "linux" ]
description
Audit a Django project for production deployment readiness — systematically check configuration, dependencies, version control, and infrastructure prerequisites before deploying to platforms like Vercel, Railway, Heroku, or any WSGI host.

02 资源文件 1

03 SKILL.md 正文

Django Production Audit

A systematic checklist-based approach to auditing a Django project before production deployment. Use this before migrating platforms (e.g., Render → Vercel + Supabase) or deploying a new project.

When to Use

  • User asks to deploy a Django project to production
  • Migrating from one hosting platform to another (e.g., Render expiry, Heroku dyno change)
  • Debugging a deployment that fails after collectstatic, migrate, or at runtime
  • Before handing off a Django project for ops/DevOps review

Workflow

1. Project Discovery

# Locate the project
find ~ -name "manage.py" -not -path "*/venv/*" -not -path "*/.venv/*" 2>/dev/null

# Verify Django
head -5 manage.py
# Must contain: os.environ.setdefault('DJANGO_SETTINGS_MODULE', '...')

2. Dependencies Audit

Read requirements.txt and check for these production essentials:

Dependency Purpose Required?
gunicorn Production WSGI server ✅ Strongly recommended on VPS/Railway. Vercel uses its own serverless wrapper.
whitenoise Serve static files without nginx ✅ Required for any platform without a CDN layer
dj-database-url Parse DATABASE_URL env var ✅ Standard for 12-factor Django
psycopg2 or psycopg[binary] PostgreSQL adapter ✅ Required for PostgreSQL
django-cors-headers CORS for API endpoints ⚠️ Needed if frontend is separate domain
djangorestframework REST API framework ⚠️ If project exposes an API
django-ratelimit Rate limiting Optional — security measure
python-decouple / python-dotenv Env file loading Optional — project may use os.getenv directly

Pitfall: If psycopg2-binary is used instead of psycopg[binary], it may fail on some serverless platforms. Prefer psycopg[binary].

3. Settings Audit

Read settings.py (or the settings module) and verify each item:

# ── Security ──
SECRET_KEY          → MUST be loaded from environment, not hardcoded
DEBUG               → MUST be False in production
ALLOWED_HOSTS       → MUST include the production domain(s)
CSRF_TRUSTED_ORIGINS  → MUST include https://yourdomain.com
CORS_ALLOWED_ORIGINS  → MUST include frontend origin if separate

# ── Database ──
DATABASES           → uses dj_database_url.config(default=os.getenv("DATABASE_URL", ...))
# Pattern:
#   DATABASES = {"default": dj_database_url.config(default=os.getenv("DATABASE_URL"))}

# ── Static Files ──
STATIC_URL          → e.g., "/static/"
STATIC_ROOT         → e.g., BASE_DIR / "staticfiles"
STATICFILES_STORAGE → "whitenoise.storage.CompressedManifestStaticFilesStorage"

# ── HTTPS / Proxy ──
SECURE_PROXY_SSL_HEADER → ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE   → True (not DEBUG)
CSRF_COOKIE_SECURE      → True (not DEBUG)
SECURE_SSL_REDIRECT     → True in production

# ── Caches (optional but recommended) ──
# Production: Redis via REDIS_URL
# Fallback: LocMemCache

Pitfall: The _env_bool() / _env_list() pattern many projects use defaults to SECURE_SSL_REDIRECT = not DEBUG. On Vercel, SSL termination happens at the edge, so this can be left as-is.

4. WSGI Entry Point

Verify wsgi.py:

import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
application = get_wsgi_application()

For Vercel serverless deployment, you'll need api/index.py (a handler wrapping WSGI — see references/vercel-wsgi-adapter.md after creation).

5. Static Files Check

# Verify collectstatic works
python manage.py collectstatic --dry-run --noinput 2>&1

# Check the target directory exists or is listed in STATIC_ROOT

6. Version Control Audit

# Check for uncommitted changes
git status --short

# Verify remote is accessible
git remote -v
git ls-remote origin HEAD   # will fail if remote is wrong/deleted

# Check .gitignore for essential exclusions
# Expected: .env, *.pyc, __pycache__/, venv/, db.sqlite3, .DS_Store, staticfiles/ (maybe)

Pitfall: If git ls-remote returns "Repository not found", the remote is stale or access was revoked. Create a new repo under the user's current GitHub account.

7. Infrastructure Availability

Tool Command Purpose
Vercel CLI vercel --version Deploy to Vercel
Supabase CLI supabase --version Manage Supabase project (optional — dashboard works too)
GitHub CLI gh auth status Verify GitHub authentication
Git git --version Push code

8. Environment Variables Checklist

Collect what the project needs (extract from settings.py os.getenv() calls and .env file):

DJANGO_SECRET_KEY        → Generate: python -c 'import secrets; print(secrets.token_urlsafe(64))'
DATABASE_URL             → Supabase PostgreSQL connection string
DJANGO_DEBUG             → false
DJANGO_ALLOWED_HOSTS     → .vercel.app,yourdomain.com
DJANGO_CSRF_TRUSTED_ORIGINS → https://yourdomain.com,https://*.vercel.app
REDIS_URL                → Optional, for caching
CLOUDINARY_CLOUD_NAME    → If using Cloudinary for media
CLOUDINARY_API_KEY       → If using Cloudinary
CLOUDINARY_API_SECRET    → If using Cloudinary

Vercel-Specific Configuration

For Vercel deployment, you need:

  1. vercel.json — configures routes, rewrites all traffic to the serverless function
  2. api/index.py — a WSGI handler that Vercel's Python runtime calls as a serverless function
  3. Build command — python manage.py collectstatic --noinput && python manage.py migrate

A reference template for these files belongs in references/vercel-wsgi-adapter.md.

Supabase PostgreSQL Setup

Two approaches:

A. Via Supabase Dashboard (recommended if no CLI):

  1. Go to https://supabase.com → New project
  2. Copy the "Connection string" (URI format) from Project Settings → Database
  3. Replace [YOUR-PASSWORD] with the database password
  4. Set as DATABASE_URL in Vercel environment variables

B. Via Supabase CLI:

supabase init
supabase link --project-ref <ref>
supabase db push

Verification

After deployment, verify:

  1. curl -I https://your-app.vercel.app/ → 200 OK
  2. Static files load (check browser or curl a known static URL)
  3. API endpoints return valid JSON
  4. Admin login works
  5. python manage.py check --deploy passes (run in CI or locally with production env vars)

Known Pitfalls

Empty .env file read

The Hermes file-read tool may block .env for security. Use cat .env via terminal instead.

Calendar invite emails return empty body

When reading Google Calendar invitation emails via gmail get, the body often comes back empty. Use the Gmail API directly with format=full and recursively extract MIME parts (text/plain or text/html) from payload.parts[].

Git remote inaccessible

If the old remote (e.g., another user's repo) returns "Repository not found", create a fresh repo under the current GitHub account and push:

gh repo create JENGA-CONNECT --private --source=. --remote=origin --push

Django version compatibility

Django 6.x may have subtle differences from 5.x/4.x. Check python -c "import django; print(django.VERSION)" in the project's venv.

04 同仓库更多 Skills