$npx -y skills add skateddu/claude-code-python-setup --skill django-verificationVerification loop for Django projects: migrations, linting, tests with coverage, security scans, and deployment readiness checks before release or PR.
| 1 | # Django Verification Loop |
| 2 | |
| 3 | Run before PRs, after major changes, and pre-deploy to ensure Django application quality and security. |
| 4 | |
| 5 | ## When to Activate |
| 6 | |
| 7 | - Before opening a pull request for a Django project |
| 8 | - After major model changes, migration updates, or dependency upgrades |
| 9 | - Pre-deployment verification for staging or production |
| 10 | - Running full environment → lint → test → security → deploy readiness pipeline |
| 11 | - Validating migration safety and test coverage |
| 12 | |
| 13 | ## Phase 1: Environment Check |
| 14 | |
| 15 | ```bash |
| 16 | # Verify Python version |
| 17 | python --version # Should match project requirements |
| 18 | |
| 19 | # Check virtual environment |
| 20 | which python |
| 21 | pip list --outdated |
| 22 | |
| 23 | # Verify environment variables |
| 24 | python -c "import os; import environ; print('DJANGO_SECRET_KEY set' if os.environ.get('DJANGO_SECRET_KEY') else 'MISSING: DJANGO_SECRET_KEY')" |
| 25 | ``` |
| 26 | |
| 27 | If environment is misconfigured, stop and fix. |
| 28 | |
| 29 | ## Phase 2: Code Quality & Formatting |
| 30 | |
| 31 | ```bash |
| 32 | # Type checking |
| 33 | mypy . --config-file pyproject.toml |
| 34 | |
| 35 | # Linting with ruff |
| 36 | ruff check . --fix |
| 37 | |
| 38 | # Formatting with black |
| 39 | black . --check |
| 40 | black . # Auto-fix |
| 41 | |
| 42 | # Import sorting |
| 43 | isort . --check-only |
| 44 | isort . # Auto-fix |
| 45 | |
| 46 | # Django-specific checks |
| 47 | python manage.py check --deploy |
| 48 | ``` |
| 49 | |
| 50 | Common issues: |
| 51 | - Missing type hints on public functions |
| 52 | - PEP 8 formatting violations |
| 53 | - Unsorted imports |
| 54 | - Debug settings left in production configuration |
| 55 | |
| 56 | ## Phase 3: Migrations |
| 57 | |
| 58 | ```bash |
| 59 | # Check for unapplied migrations |
| 60 | python manage.py showmigrations |
| 61 | |
| 62 | # Create missing migrations |
| 63 | python manage.py makemigrations --check |
| 64 | |
| 65 | # Dry-run migration application |
| 66 | python manage.py migrate --plan |
| 67 | |
| 68 | # Apply migrations (test environment) |
| 69 | python manage.py migrate |
| 70 | |
| 71 | # Check for migration conflicts |
| 72 | python manage.py makemigrations --merge # Only if conflicts exist |
| 73 | ``` |
| 74 | |
| 75 | Report: |
| 76 | - Number of pending migrations |
| 77 | - Any migration conflicts |
| 78 | - Model changes without migrations |
| 79 | |
| 80 | ## Phase 4: Tests + Coverage |
| 81 | |
| 82 | ```bash |
| 83 | # Run all tests with pytest |
| 84 | pytest --cov=apps --cov-report=html --cov-report=term-missing --reuse-db |
| 85 | |
| 86 | # Run specific app tests |
| 87 | pytest apps/users/tests/ |
| 88 | |
| 89 | # Run with markers |
| 90 | pytest -m "not slow" # Skip slow tests |
| 91 | pytest -m integration # Only integration tests |
| 92 | |
| 93 | # Coverage report |
| 94 | open htmlcov/index.html |
| 95 | ``` |
| 96 | |
| 97 | Report: |
| 98 | - Total tests: X passed, Y failed, Z skipped |
| 99 | - Overall coverage: XX% |
| 100 | - Per-app coverage breakdown |
| 101 | |
| 102 | Coverage targets: |
| 103 | |
| 104 | | Component | Target | |
| 105 | |-----------|--------| |
| 106 | | Models | 90%+ | |
| 107 | | Serializers | 85%+ | |
| 108 | | Views | 80%+ | |
| 109 | | Services | 90%+ | |
| 110 | | Overall | 80%+ | |
| 111 | |
| 112 | ## Phase 5: Security Scan |
| 113 | |
| 114 | ```bash |
| 115 | # Dependency vulnerabilities |
| 116 | pip-audit |
| 117 | safety check --full-report |
| 118 | |
| 119 | # Django security checks |
| 120 | python manage.py check --deploy |
| 121 | |
| 122 | # Bandit security linter |
| 123 | bandit -r . -f json -o bandit-report.json |
| 124 | |
| 125 | # Secret scanning (if gitleaks is installed) |
| 126 | gitleaks detect --source . --verbose |
| 127 | |
| 128 | # Environment variable check |
| 129 | python -c "from django.core.exceptions import ImproperlyConfigured; from django.conf import settings; settings.DEBUG" |
| 130 | ``` |
| 131 | |
| 132 | Report: |
| 133 | - Vulnerable dependencies found |
| 134 | - Security configuration issues |
| 135 | - Hardcoded secrets detected |
| 136 | - DEBUG mode status (should be False in production) |
| 137 | |
| 138 | ## Phase 6: Django Management Commands |
| 139 | |
| 140 | ```bash |
| 141 | # Check for model issues |
| 142 | python manage.py check |
| 143 | |
| 144 | # Collect static files |
| 145 | python manage.py collectstatic --noinput --clear |
| 146 | |
| 147 | # Create superuser (if needed for tests) |
| 148 | echo "from apps.users.models import User; User.objects.create_superuser('admin@example.com', 'admin')" | python manage.py shell |
| 149 | |
| 150 | # Database integrity |
| 151 | python manage.py check --database default |
| 152 | |
| 153 | # Cache verification (if using Redis) |
| 154 | python -c "from django.core.cache import cache; cache.set('test', 'value', 10); print(cache.get('test'))" |
| 155 | ``` |
| 156 | |
| 157 | ## Phase 7: Performance Checks |
| 158 | |
| 159 | ```bash |
| 160 | # Django Debug Toolbar output (check for N+1 queries) |
| 161 | # Run in dev mode with DEBUG=True and access a page |
| 162 | # Look for duplicate queries in SQL panel |
| 163 | |
| 164 | # Query count analysis |
| 165 | django-admin debugsqlshell # If django-debug-sqlshell installed |
| 166 | |
| 167 | # Check for missing indexes |
| 168 | python manage.py shell << EOF |
| 169 | from django.db import connection |
| 170 | with connection.cursor() as cursor: |
| 171 | cursor.execute("SELECT table_name, index_name FROM information_schema.statistics WHERE table_schema = 'public'") |
| 172 | print(cursor.fetchall()) |
| 173 | EOF |
| 174 | ``` |
| 175 | |
| 176 | Report: |
| 177 | - Number of queries per page (should be < 50 for typical pages) |
| 178 | - Missing database indexes |
| 179 | - Duplicate queries detected |
| 180 | |
| 181 | ## Phase 8: Static Assets |
| 182 | |
| 183 | ```bash |
| 184 | # Check for npm dependencies (if using npm) |
| 185 | npm audit |
| 186 | npm audit fix |
| 187 | |
| 188 | # Build static files (if using webpack/vite) |
| 189 | npm run build |
| 190 | |
| 191 | # Verify static files |
| 192 | ls -la staticfiles/ |
| 193 | python manage.py findstatic css/style.css |
| 194 | ``` |
| 195 | |
| 196 | ## Phase 9: Configuration Review |
| 197 | |
| 198 | ```python |
| 199 | # Run in Python shell to verify settings |
| 200 | python manage.py shell << EOF |
| 201 | from django.conf import settings |
| 202 | import os |
| 203 | |
| 204 | # Critical checks |
| 205 | checks = { |
| 206 | 'DEBUG is False': n |