Connect Django to Bugsink

When a Django request fails, Bugsink shows you the exception, the application frame that raised it, and the request that reached the view.

This guide covers the initial setup and Django’s automatic capture of unhandled view exceptions. You’ll add the integration to an existing project, then make one request fail to confirm that it reaches Bugsink.

To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the SDK

Install the open-source Sentry SDK with its Django support in the environment your application already uses. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project.

python -m pip install --upgrade "sentry-sdk[django]"

Configure Django

Import the SDK and Django integration near the top of your settings module:

import os

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

Initialize it in the same file. Reading the DSN from the environment keeps it out of source control:

sentry_sdk.init(
    dsn=os.environ["SENTRY_DSN"],
    integrations=[DjangoIntegration()],
)

Set SENTRY_DSN in the environment where Django runs. Use the DSN you copied from your Bugsink project:

export SENTRY_DSN=https://key@bugsink.example/1

Trigger an unhandled exception

If a Django view raises an exception and does not catch it, the integration reports it automatically. There is no SDK call inside the view. To verify the setup, this checkout view raises an exception for a missing product:

class ProductNotFound(LookupError):
    pass


def checkout(request, sku):
    try:
        product = INVENTORY[sku]
    except KeyError:
        raise ProductNotFound(f"Product {sku} is not in inventory") from None
    return JsonResponse({"reserved": product["name"]})

The application routes /checkout/<sku>/ to that view:

from django.urls import path

from . import views


urlpatterns = [
    path("", views.index),
    path("checkout/<str:sku>/", views.checkout),
]

Start Django as usual, then request a product that does not exist through that URL:

python manage.py runserver
:::bash
curl http://127.0.0.1:8000/checkout/django-missing/

Django returns a 500 response. The integration reports the exception while Django handles that response normally.

See the error in Bugsink

Open your Bugsink project and select the new ProductNotFound issue. Its event points to the failing line in the Django view and includes the GET request.

Bugsink preview

That’s it: unhandled Django view exceptions will now be reported to Bugsink.

The integration runs around Django’s request handling, so the view itself stays ordinary Django code. An unhandled exception includes its Python stack, the application source frame, and the HTTP request that reached the view.

If your application catches an exception itself, Django no longer sees it as an unhandled request error. You can still report it explicitly with capture_exception().