Django Python

Our Django integration lets you instrument individual HTTP requests by adding a dedicated middleware to your application. Please note that Blackfire supports Django 1.1 and higher.

Caution

Blackfire Django integration has compatibility issues with the Django debug toolbar. You may consider disabling the Django debug middleware when using Blackfire.

Automatic Instrumentation

The recommended way to use Blackfire with Django is to use the blackfire-python command, as it configures the needed bits for you.

Run your webserver with blackfire-python command:

blackfire-python python manage.py runserver

Or with gunicorn:

blackfire-python gunicorn myapp.wsgi

Manual Installation

If you prefer configuring Django manually, you can add the following call manually within your code:

1
2
import blackfire
blackfire.patch_all()

This call should be made as early as possible in the lifecycle of an application, ideally before any other import statements.

Then, restart your server.

Caution

We used to provide a Django middleware along with the Blackfire Python SDK, blackfire.middleware.DjangoMiddleware.

This middleware is now deprecated in favor of the blackfire-python or the blackfire.patch_all() call. Using the middleware will trigger a deprecation warning.

Profiling HTTP Requests

You can use the blackfire curl command to profile specific requests:

1
blackfire curl http://localhost:8000/polls/1/results

You can also use one of our browser extensions for Firefox or Chrome.

Read more about profiling web applications with a browser, or profiling with the CLI.