
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
Output
- Related Articles
- MongoDB query for ranking / search count?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Execute MySQL query from the terminal without printing results?
- Get multiple count in a single MySQL query for specific column values
- Program to count number of similar substrings for each query in Python
- Operating System Debugging
- Debugging ReactJS applications
- MongoDB query to sum specific key values with terminal commands?
- Debugging and Error Boundary in React.js
- 20 Useful Terminal Emulators for Linux
- Debugging JavaScript using Firebug
- Using djoser in Django for token authentication without views
- Debugging an Asynchronous RFC in SAP ABAP
- How to implement django-material in your Django project?
- MySQL query to count rows in multiple tables
