Skip to main content

Django Stats Middleware

Django is one of the most popular Python web frameworks today.

When a Django site seems slow, it's nice to put some real number to to that. The Django Debug Toolbar is the go-to middleware solution for diagnosing Django performance among other things, but it is rather large, and slow itself, adding significantly to the load time of your pages. So it's in a bit of catch-22 bind for simple performance overviews.

For that reason I wrote this tiny little lightweight piece of middleware that reports at the bottom of every page a single line reporting some basic timing stats.

  • Total Time: The time from the request arriving to the response being delivered.
  • Python Time: Time spent running Python code
  • DB Time: Time spent waiting on database queries
  • Number of Queries: The number of database queries run

Where:

​ Python Time + DB Time = Total Time

Here's an example:

sample

To use it just put it at the top of your Django Middleware stack:

MIDDLEWARE = (
    'django_stats_middleware.StatsMiddleware',
	...

That way Total Time will include the time spent in all other middleware as well as your site code.

It includes some minimal CSS and to include that in your site include it as an app (so Django knows to collect static files from it):

    INSTALLED_APPS += (
        'django_stats_middleware',
    )

and in your template load the CSS:

    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'django-stats-middleware/css/default.css' %}" />

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_stats_middleware-0.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_stats_middleware-0.4-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file django_stats_middleware-0.4.tar.gz.

File metadata

  • Download URL: django_stats_middleware-0.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for django_stats_middleware-0.4.tar.gz
Algorithm Hash digest
SHA256 929e697b472f1c6177660b746011dd96503f6dafc6e7fc4a90322abc72636478
MD5 a6b8a12d0f39510242f6fb9af9d6bf43
BLAKE2b-256 71ac37f7755073cdab62ad223c057b058fe17baa653822bce3963a1372cdc925

See more details on using hashes here.

File details

Details for the file django_stats_middleware-0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_stats_middleware-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6f5227473fd74a179d3cbdab994cbd697e98fc83bb1407f08cad43dd8ea53cea
MD5 e4fe15c263fa23855bdacc5857a18f9d
BLAKE2b-256 cddd8031632de3ec72c918a7370676f65f70c264fc4259d9d34595951870a278

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4 This release

2 files

0.3

2 files

0.2

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page