django-querycount is a Django middleware designed to provide real-time database query monitoring directly in the `runserver` console. It helps developers identify and optimize performance bottlenecks, such as N+1 query problems, by tracking the number of SQL queries executed for each request. This tool is specifically intended for development environments and is hardcoded to operate only when Django's `DEBUG` setting is `True`. The current version is 0.8.3, released in January 2023, and it remains an actively used utility in the Django community for performance debugging.
pip install django-querycountVerified import paths — ran on the pinned version, not inferred.
To enable `django-querycount`, add `querycount.middleware.QueryCountMiddleware` to your `MIDDLEWARE` list in your Django project's `settings.py`. Ensure that `DEBUG = True` for `django-querycount` to function. You can also customize its behavior by defining a `QUERYCOUNT` dictionary in your settings.
Ensure `DEBUG = True` in your `settings.py` during development where you wish to use django-querycount. Do not enable DEBUG in production environments.
Migrate your `QUERYCOUNT_THRESHOLDS` setting to `QUERYCOUNT = { 'THRESHOLDS': { ... } }`.Remove or comment out `querycount.middleware.QueryCountMiddleware` from `MIDDLEWARE` in production settings, or manage your `DEBUG` setting carefully.
Verify the exact package name (`django-querycount`) and the correct import path (`querycount.middleware.QueryCountMiddleware`) to ensure you are using the intended library for middleware-based query counting.