4 ms·
Related question: is there an easy build-in way in Django to write to stdout a count of DB queries made for a request?
by yaix 14y ago
Related question: is there an easy build-in way in Django to write to stdout a count of DB queries made for a request?
- funksta 14y agoI haven't worked with Django in a bit so my memory is foggy, but if settings.DEBUG is true, you should be able to do something like: from django.db import connection print len(connection.queries) Put that in a middleware class's process_response() and it should print the query count for every request.
- stevejalim 14y agoUse django-devserver https://github.com/dcramer/django-devserver https://github.com/dcramer/django-devserver
- GeneralMaximus 14y agoI second django-debugserver. This is one of those nifty packages you wish were included with the default Django distribution. More than once, it has helped me find and fix query-related issues. Highly recommended.
- rfurmani 14y agoOne option is to use the debug_toolbar package. You can set it up to display only when testing or only when an admin is logged in, and it will give you a convenient bar on the right side that shows exactly how long everything took, along with all SQL queries. This allowed me to greatly cut down the number of queries by judiciously using fetch_related.