Skip to content

Instantly share code, notes, and snippets.

@julen
Created August 1, 2013 07:28
Show Gist options
  • Save julen/6129184 to your computer and use it in GitHub Desktop.
Save julen/6129184 to your computer and use it in GitHub Desktop.
Printing human-readable SQL queries to the console in scenarios where the django-debug-toolbar isn't available.
import sqlparse
qs = MyObject.objects.filter(foo='bar', baz__startswith='baz')
sql, params = qs.query.sql_with_params()
print sqlparse.format(str(sql % params),
reindent=True, keyword_case='upper')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment