|
| 1 | +# shimkit framework django |
| 2 | + |
| 3 | +Django-specific helpers. Third recipe under the `framework` |
| 4 | +parent. Same shape as the Laravel + Symfony recipes; adjusted |
| 5 | +for Django's conventions. |
| 6 | + |
| 7 | +## Commands |
| 8 | + |
| 9 | +| Command | Purpose | |
| 10 | +|---------|---------| |
| 11 | +| `shimkit framework django` | Menu. | |
| 12 | +| `shimkit framework django perms PATH [--group G]` | MODERATE. Fix `media/` + `staticfiles/` permissions. | |
| 13 | +| `shimkit framework django env PATH [--name N] [--debug/--no-debug] [--db D]` | MODERATE. Scaffold `.env` with `SECRET_KEY` + `DATABASE_URL`. | |
| 14 | +| `shimkit framework django migrate PATH` | Wraps `python manage.py migrate --no-input`. | |
| 15 | +| `shimkit framework django manage -- <args>` | Passthrough to `python manage.py`. | |
| 16 | + |
| 17 | +Universal flags before the subcommand (`--quiet`, `--verbose`, |
| 18 | +`--log-file`, `--no-color`, `--color`, `--no-input`); per-command |
| 19 | +flags after (`--json`, `--dry-run`, `--yes`, `--force`). |
| 20 | + |
| 21 | +## Differences from Laravel + Symfony |
| 22 | + |
| 23 | +| Aspect | Laravel | Symfony | Django | |
| 24 | +|--------|---------|---------|--------| |
| 25 | +| Writable tree | `storage/` + `bootstrap/cache/` | `var/` | `media/` + `staticfiles/` | |
| 26 | +| App secret | `APP_KEY=base64:...` | `APP_SECRET=...` (hex) | `SECRET_KEY=...` (Django alphabet) | |
| 27 | +| Env file | `.env` (gitignored) | `.env.local` (gitignored) | `.env` (django-environ / decouple convention) | |
| 28 | +| Console | `artisan` (root) | `bin/console` | `manage.py` (root) | |
| 29 | +| Console runtime | `php` | `php` | `python` | |
| 30 | +| Scheduler | `schedule:run` every minute | none — use `shimkit cron add` | none — use `shimkit cron add` | |
| 31 | + |
| 32 | +## perms |
| 33 | + |
| 34 | +`media/` (user uploads) and `staticfiles/` (collectstatic target) |
| 35 | +are the canonical writable trees in modern Django layouts. |
| 36 | +`staticfiles/` typically doesn't exist on a fresh project until |
| 37 | +the first `collectstatic` — shimkit warns about that and runs |
| 38 | +the global `chmod` passes regardless. |
| 39 | + |
| 40 | +Group detection: `getent group <name>` on Linux, `dscl . -read |
| 41 | +/Groups/<name>` on macOS, `grp.getgrnam()` Python fallback. |
| 42 | + |
| 43 | +```bash |
| 44 | +shimkit framework django perms --yes ./my-django-app |
| 45 | +shimkit framework django perms --yes --group staff ./my-django-app # macOS |
| 46 | +shimkit framework django perms --dry-run ./my-django-app |
| 47 | +``` |
| 48 | + |
| 49 | +## env |
| 50 | + |
| 51 | +Writes `.env` with a generated `SECRET_KEY` + `DATABASE_URL` + |
| 52 | +sensible dev defaults. **Refuses to overwrite** an existing |
| 53 | +`.env`. The format is django-environ / python-decouple |
| 54 | +compatible: `KEY=value` lines. `DATABASE_URL` follows the |
| 55 | +Heroku / dj-database-url convention. |
| 56 | + |
| 57 | +`SECRET_KEY` is 50 chars from Django's documented alphabet — |
| 58 | +matches what `django.core.management.utils.get_random_secret_key()` |
| 59 | +would emit, but shimkit doesn't depend on Django being installed |
| 60 | +to scaffold the file. |
| 61 | + |
| 62 | +Default DB engine is **postgres** (Django's most-shipped pairing). |
| 63 | +Override with `--db mysql` or `--db mariadb`. |
| 64 | + |
| 65 | +| `--db` | URL prefix | Port | |
| 66 | +|------------|------------|------| |
| 67 | +| `postgres` (default) | `postgres://` | 15432 | |
| 68 | +| `mysql` | `mysql://` | 13306 | |
| 69 | +| `mariadb` | `mysql://` | 13307 | |
| 70 | + |
| 71 | +```bash |
| 72 | +shimkit db postgres up |
| 73 | +shimkit framework django env --yes --db postgres ./my-app |
| 74 | + |
| 75 | +# DEBUG=False for a more prod-like local |
| 76 | +shimkit framework django env --yes --no-debug ./my-app |
| 77 | +``` |
| 78 | + |
| 79 | +The env file also lists a commented-out `REDIS_URL` line as a |
| 80 | +hint pointing the user at `shimkit db redis up` (v0.15.0+). |
| 81 | + |
| 82 | +## migrate |
| 83 | + |
| 84 | +Sugar for `manage migrate --no-input`: |
| 85 | + |
| 86 | +```bash |
| 87 | +shimkit framework django migrate ./my-app |
| 88 | +shimkit framework django migrate --in-container --stack myapp ./my-app |
| 89 | +``` |
| 90 | + |
| 91 | +## manage |
| 92 | + |
| 93 | +Generic passthrough to `python manage.py`. Host execution by |
| 94 | +default — preflights `python` via |
| 95 | +`shimkit.core.version.preflight`, exits 69 with the remediation |
| 96 | +hint when `python` is missing. `--in-container` routes through |
| 97 | +`shimkit stack lemp`'s php-fpm container (which has `python` |
| 98 | +installed via the upstream PHP-FPM image's base layers). |
| 99 | + |
| 100 | +```bash |
| 101 | +shimkit framework django manage --project ./my-app -- runserver 0.0.0.0:8000 |
| 102 | +shimkit framework django manage --project ./my-app -- createsuperuser |
| 103 | +shimkit framework django manage --project ./my-app -- collectstatic --no-input |
| 104 | +``` |
| 105 | + |
| 106 | +`--project` defaults to the current working directory. |
| 107 | + |
| 108 | +## End-to-end example |
| 109 | + |
| 110 | +```bash |
| 111 | +# 1. Database |
| 112 | +shimkit db postgres up |
| 113 | + |
| 114 | +# 2. Optional: Redis cache / Channels |
| 115 | +shimkit db redis up |
| 116 | + |
| 117 | +# 3. Scaffold env + fix perms |
| 118 | +shimkit framework django env --yes --db postgres ./my-app |
| 119 | +shimkit framework django perms --yes ./my-app |
| 120 | + |
| 121 | +# 4. Migrate + create superuser |
| 122 | +shimkit framework django migrate ./my-app |
| 123 | +shimkit framework django manage --project ./my-app -- createsuperuser |
| 124 | + |
| 125 | +# 5. Run the dev server |
| 126 | +shimkit framework django manage --project ./my-app -- runserver |
| 127 | +``` |
| 128 | + |
| 129 | +## Configuration |
| 130 | + |
| 131 | +```json |
| 132 | +{ |
| 133 | + "tools": { |
| 134 | + "framework": { |
| 135 | + "django": { |
| 136 | + "web_group": "www-data", |
| 137 | + "file_mode": "664", |
| 138 | + "dir_mode": "775", |
| 139 | + "writable_dirs": ["media", "staticfiles"], |
| 140 | + "default_debug": true |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +Override `web_group` per host. Add `writable_dirs` entries if |
| 148 | +your app writes outside `media/` + `staticfiles/`. |
| 149 | + |
| 150 | +## Exit codes |
| 151 | + |
| 152 | +| Code | Meaning | |
| 153 | +|-----:|---------| |
| 154 | +| 0 | success | |
| 155 | +| 1 | bad path, missing `manage.py`, refusing overwrite, prompt cancelled | |
| 156 | +| 2 | Typer usage error | |
| 157 | +| 69 | `EX_UNAVAILABLE` — wrong platform or missing `python` for `manage`/`migrate` | |
| 158 | +| 130 | SIGINT | |
| 159 | + |
| 160 | +## Platform support |
| 161 | + |
| 162 | +| Platform | Status | |
| 163 | +|----------|--------| |
| 164 | +| macOS | full. Dev account typically owns the project, so `chgrp` is no-op'd unless `--group` is passed. | |
| 165 | +| Linux | full. Targets `www-data` by default; override with `--group`. | |
| 166 | +| WSL | works (Linux path). | |
| 167 | +| Windows | out of charter (use WSL). | |
0 commit comments