
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Django Query Count in Terminal for Debugging
In this article, we are going to use a library in Django to see a brief report of database query count in terminal which can be used for debugging. It will provide a brief tabular report of every hit on any model object and print it on every hit, whether it is read or write. It will also calculate the response and request.
Example
Do some basic stuff like setting apps and urls.
Install the django-querycount module −
pip install django-querycount
In settings.py, add this −
MIDDLEWARE += [ 'querycount.middleware.QueryCountMiddleware', ]
This will enable the functionality of library and allow us to use it at runtime of project. It is really beneficial.
Now, setup your debugging channel.
At every query, you will see a table report on the terminal. Note that it only works when your debug is true. You will see the report only when you make any type of contact with models, this is a debug tool after all.
One more thing to keep in mind is that it will give a report of certain model when you make hit on that model.