Skip to content

Django integration guide

Typical installation time: 5 minutes

Hi there! You’ve found Honeybadger’s guide to Django error tracking and performance monitoring. Once installed, Honeybadger will automatically report errors and performance insights from your Django application.

Install the honeybadger Python package with pip (or add it to your requirements.txt):

Terminal window
pip install honeybadger

In your Django application, add the Honeybadger Django middleware to the top of your MIDDLEWARE config variable in settings.py:

MIDDLEWARE = [
'honeybadger.contrib.DjangoHoneybadgerMiddleware',
# ... your other middleware
]

It’s important that the Honeybadger middleware is at the top, so that it wraps the entire request process, including all other middleware.

Add a new HONEYBADGER config variable to your settings.py:

HONEYBADGER = {
'API_KEY': 'PROJECT_API_KEY',
'INSIGHTS_ENABLED': True
}

See the Configuration reference for additional info.

To test that Honeybadger is working, you can create a simple test exception:

from honeybadger import honeybadger
try:
raise Exception("Honeybadger test exception")
except Exception as e:
honeybadger.notify(e)

If the installation is working correctly, this error should appear in your Honeybadger dashboard.

The DjangoHoneybadgerMiddleware integrates with Django’s request/response cycle to automatically capture errors and performance data. When an exception occurs, it automatically adds the following information to the error report:

  • URL: The full URL the request was sent to
  • Component: The Django app name (if available)
  • Action: The view function name
  • Params: GET or POST parameters (filtered for sensitive data)
  • Session: Session data (filtered for sensitive data)
  • CGI data: Request headers and environment variables (filtered for sensitive data)
  • Context: Username and user ID when request.user is authenticated

When Insights is enabled, the middleware automatically tracks:

  • Request performance: Response times, status codes, and view information
  • Database queries: Query duration and SQL statements (with configurable filtering)
  • Request correlation: Generates or captures request IDs for tracing across systems

Honeybadger isn’t just for errors and application data! You can use our syslog, Vector, or PaaS integrations to send additional data from your infrastructure to Honeybadger Insights, where you can query, visualize, and analyze all of your production data in one place.