A simple middleware aimed to capture all queries in a request and provide basic SQL profiling such as execution time, execution plan, and query traceback.
This package is only intended to run in development mode for non-sqlite database.
Currently, this package only tested in projects that uses psycopg2 (postgres) as default database engine.
-
Get the package from pypi:
pip install django-sql-middleware
-
In
settings.py
add:INSTALLED_APPS = [ # your other apps "sqlmiddleware" ] MIDDLEWARE = [ # your other middlewares ] if DEBUG: MIDDLEWARE.append("sqlmiddleware.middlewares.LogSQLMiddleware")
-
Register urls in
your_project/urls.py
:from django.urls import include, path urlpatterns = [ # other urls, path("__sql/", include("sqlmiddleware.urls")), ]
-
Run
collectstatic
to serve included css and js assets:./manage.py collectstatic
-
Start the development server:
./manage.py runserver
-
you should be able to access
localhost:8000/__sql
in your browser.