Skip to main content

Django middleware that shows you how fast your pages load, right in your browser.

Project description

django-chronos PyPI version

Django middleware that shows you how fast your pages load, right in your browser. Displays request timing and query counts for your views and middleware.

django-chronos

Installation

Install Django Chronos using pip:

pip install django-chronos

Quick Start

  1. Add to INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
    # ... your other apps
    'django_chronos',
]
  1. Add middleware to your Django settings (order matters):
MIDDLEWARE = [
    'django_chronos.middleware.ChronosStartMiddleware',  # Must be first
    # ... your other middleware
    'django_chronos.middleware.ChronosEndMiddleware',    # Must be last
]
  1. Run your Django application and visit any page. You'll see a stats overlayed in the bottom-left corner.

Configuration

CHRONOS_SHOW_IN_PRODUCTION (default: False)

Controls whether stats are shown in production mode (DEBUG=False). Stats are only shown to superusers in production. Stats always show in DEBUG mode.

CHRONOS_SHOW_IN_PRODUCTION = True

CHRONOS_SWAP_METHOD (default: 'prepend')

Controls how the stats are inserted into the response:

  • 'prepend': Insert stats before the target
  • 'append': Insert stats after the target
  • 'replace': Replace the target with stats
CHRONOS_SWAP_METHOD = 'append'

CHRONOS_SWAP_TARGET (default: '</body>')

The string in the response where stats will be swapped in. Stats will not be displayed if this string does not exist in the response.

CHRONOS_SWAP_TARGET = '</body>'

Customizing the Stats Display

You can override the default stats display by creating your own chronos/chronos.html template in your Django project.

The template receives the following context variables:

  • middleware_cpu_time, middleware_sql_time, middleware_sql_count, middleware_total_time
  • view_cpu_time, view_sql_time, view_sql_count, view_total_time
  • total_cpu_time, total_sql_time, total_sql_count, total_time

Note: In production mode, the *_sql_time and *_sql_count variable values will be zero (why?). You can wrap these variables in {% if debug %} blocks to stop them from displaying in production.

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Appreciation

Adam Hill for the inspiration via his Mastodon thread.

Project details


Download files

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

Source Distribution

django_chronos-250808.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

django_chronos-250808-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file django_chronos-250808.tar.gz.

File metadata

  • Download URL: django_chronos-250808.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for django_chronos-250808.tar.gz
Algorithm Hash digest
SHA256 9241474d3bb4bae82b7824bd94ef14edc2ca921675e64467ca42bda2c44cbd8b
MD5 757b1c36c7bf754e1d917a9edef4bd69
BLAKE2b-256 4f50506f95524c427a2f0cfd418e56bc6edd2a6da7a370cf88b8f3b71d23985e

See more details on using hashes here.

File details

Details for the file django_chronos-250808-py3-none-any.whl.

File metadata

File hashes

Hashes for django_chronos-250808-py3-none-any.whl
Algorithm Hash digest
SHA256 bf6db1c0d29a895c34457d5d00f695824c45622d816d4818e89429fb3766b03b
MD5 58e0f028b90a0e091eb2a9667e617475
BLAKE2b-256 5df96ddc60e99d2390880a86f86c63206036d8b00c3bd213c36f5c3ccbb1f4ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page