Django: Custom Middleware for Alerting High Database Querying

In this post I will show you how you can implement a custom middleware that you can use in your development environment to monitor queries to the database in your views when developing Django applications.

Let's begin by creating a file (a nice convention) where we will place our new middleware. The middleware is relatively simple and small, this is how it looks like:

You can customize the threshold value as you see fit.

Finally add the new middleware to the MIDDLEWARE configuration in your settings:

    # Other middleware...


comments powered by Disqus