django-cprofile-middleware
raw JSON → 1.0.5 verified Fri May 01 auth: no python
A Django middleware that uses cProfile to profile views, triggered by a query parameter. Version 1.0.5 is the latest, with infrequent releases.
pip install django-cprofile-middleware Common errors
error ModuleNotFoundError: No module named 'cprofile_middleware' ↓
cause Misspelled package name or forgot to install.
fix
Run 'pip install django-cprofile-middleware' and check spelling in imports.
error Profiling output not showing ↓
cause Missing ?prof query parameter or middleware not registered properly.
fix
Add 'cprofile_middleware.middleware.cProfileMiddleware' to MIDDLEWARE and append ?prof to the URL.
Warnings
gotcha Using path-based import string instead of dotted class path may cause import errors. ↓
fix Use the full dotted path as shown in quickstart, not a shorter alias.
gotcha Middleware does not require Django's debug mode; it can be used in production if the ?prof parameter is known. ↓
fix Remove or guard the middleware in production if profiling should be disabled.
Imports
- cProfileMiddleware
from cprofile_middleware.middleware import cProfileMiddleware
Quickstart
# settings.py
MIDDLEWARE = [
...
'cprofile_middleware.middleware.cProfileMiddleware',
]
# Add to a view's URL (optional for fine control):
# ?prof to enable profiling