Skip to content

Instantly share code, notes, and snippets.

@FeroxTL
FeroxTL / SQLPrintingMiddleware.py
Last active August 6, 2017 18:59 — forked from vstoykov/SQLPrintingMiddleware.py
Django Middleware to print sql queries in debug console
"""
Originaly code was taken from http://djangosnippets.org/snippets/290/
But I was made some improvements like:
- print URL from what queries was
- don't show queries from static URLs (MEDIA_URL and STATIC_URL, also for /favicon.ico).
- If DEBUG is False tell to django to not use this middleware
- Remove guessing of terminal width (This breaks the rendered SQL)
"""
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings