1 2 3 4 5 6 | import sqlparse
def print_sql(qs):
q = qs.query.as_sql()
statement = q[0] % q[1]
print sqlparse.format(statement, reindent=True, keyword_case='upper')
|
More like this
- DebugFooter middleware with Pygments sql syntax highlighting by monolar 3 years, 8 months ago
- print SQL statements by zuzelvp 2 years ago
- SQL Log To Console Middleware by davepeck 2 years, 6 months ago
- Format transition middleware by limodou 4 years, 11 months ago
- Serializing booleans correctly when doing dumpdata from a MySQL database using Django 0.96 by chrj 3 years, 6 months ago
Comments
You might want to wrap this with something so that this doesn't get used in non-development mode. For example:
#
This should work in Django 1.2:
#