Lightweight Django middleware for real-time request logging during development.
Project description
django-watch
Lightweight Django middleware for real-time request logging during development.
Prints the resolved view's source file, function name, line number, HTTP status, SQL stats, memory usage, and wall-clock timing straight to your terminal — no extra configuration required.
Each request/response pair is colour-coded with a matching emoji so nested or interleaved requests are easy to follow at a glance.
Installation
pip install django-watch
Quick start
Add the middleware at the end of your settings.py:
if DEBUG:
INSTALLED_APPS += ("django_watch",)
MIDDLEWARE += ("django_watch.middleware.WatchMiddleware",)
Open your development console and you will see output like this:
🟢 GET main/views.py • profile • Line 191
🟢 kwargs: {'username': 'sobolev'}
🟢 headers: Content-Type: text/html | Accept: */*
🟢 GET main/views.py • profile [ OK ] • STATUS 200 • 0.12s • SQL 5q/0.03s • 1 dupes • 2.4KB text/html • mem Δ+128KB
🟢 response headers: Content-Type: text/html | Cache-Control: max-age=0
🔵 POST main/views.py • login • Line 42
🔵 request.POST: <QueryDict: {'email': ['user@example.com']}>
🔵 headers: Content-Type: application/x-www-form-urlencoded
🔵 POST main/views.py • login [ OK ] • STATUS 302 • 0.05s • SQL 2q/0.01s • 0B text/html
🔵 response headers: Location: /dashboard/
🟣 GET main/views.py • dashboard • Line 80
🟣 GET main/views.py • dashboard [ OK ] • STATUS 200 • 0.31s • SQL 8q/0.09s • 3 dupes • 12.1KB text/html
🟣 response headers: Content-Type: text/html; charset=utf-8
Colours and emoji rotate automatically: 🟢 🔵 🟣 🩵 ⚪ 💚 💙 💜 — red is reserved for exceptions.
What it logs
| Phase | Information |
|---|---|
| Before view | HTTP method, source file, view function, line number |
| Request data | args, kwargs, GET, POST, raw body (truncated) |
| Request headers | Authorization (masked), Content-Type, Accept, X-Requested-With |
| After view | Status code, total time, response size and Content-Type |
| Response headers | Content-Type, Location, Cache-Control, Set-Cookie, X-Frame-Options |
| SQL | Query count, total query time, duplicate query count (N+1 detection) |
| Memory | RSS delta before/after view |
| On exception | Full Python traceback with ❌ marker |
Running tests
uv sync
uv run pytest
The test suite uses an in-memory SQLite database and covers the full middleware chain: view resolution logging, SQL query counting with duplicate detection, request header output, response metadata, emoji rotation, and exception tracebacks.
Requirements
- Python 3.8+
- Django 3.2+
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_watch-0.6.1.tar.gz.
File metadata
- Download URL: django_watch-0.6.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61578057220555da3fd5758cc1252a7f72619020a6e2ff3f918d7b5b1f0ba9bf
|
|
| MD5 |
231f9249915e68120a7b523146a09911
|
|
| BLAKE2b-256 |
5374fb4b93e28a213e95294c9a0ec66c80a0fa19dddf6827260977a6a7e8dca5
|
File details
Details for the file django_watch-0.6.1-py3-none-any.whl.
File metadata
- Download URL: django_watch-0.6.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d54386bd76f9ce18263f48396fd56ee4289d619e249c3fc71a0fa61a21b7777
|
|
| MD5 |
222bf76342ecce62389b67e7c18daa34
|
|
| BLAKE2b-256 |
5e8ee388f86d4dd24330b650e40621611f1ec791795ee5e5062daeaa1a036346
|