Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dump the sql that django generates
import sqlparse
from django.db import connection
from django.core.signals import request_finished
def finished(sender, **kwargs):
for query in connection.queries:
print "\n" + "(" + query['time'] + " s) " + sqlparse.format(query['sql'], reindent=True, keyword_case="upper") + "\n"
if len(connection.queries) > 0:
print "NUMBER OF DB QUERIES FOR THIS REQUEST:", len(connection.queries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.