Codementor Events

How many database queries is my django rest api is calling?

Published Feb 25, 2020
  1. Run your django project locally in debug ( in visual studio)
  2. Place debug breakpoints at the points of the returns in the functions that would be called when you hit the api.
  3. Hit the api with appropriate payload.
  4. Run the following in the debug terminal of VS Code.

from django.db import connection
connection.queries

len(connection.queries)

  • Above steps will give the database queries.

There is another way of capturing this information.
We can do this by creating a middleware. The middleware would log this information in a file. This will be a topic for another post.

Discover and read more posts from Rajaram K
get started
post commentsBe the first to share your opinion
Show more replies