Skip to content
English

Blog · 31 October 2026

Error monitoring for Python and Django

Django, Flask, FastAPI and Celery, with one line of configuration.

On an error, Django e-mails a traceback to the ADMINS, if that is set up correctly at all. At ten errors a minute your mailbox fills up, and an error in a Celery task you don't see at all. With the Sentry Python SDK and errors.nl errors are grouped, with the request, the view and the local variables.

1. Create a project

Create a free account at errors.nl (or log in), create an organization and a project and copy the DSN. It looks like https://<key>@ingest.errors.nl/<project>.

2. Install the SDK

pip install "sentry-sdk[django]"

Using Flask or FastAPI? Install sentry-sdk[flask] or sentry-sdk[fastapi].

3. Turn it on in settings.py

import os
import sentry_sdk

sentry_sdk.init(
    dsn=os.environ.get("SENTRY_DSN"),
    environment=os.environ.get("ENVIRONMENT", "production"),
    release=os.environ.get("SENTRY_RELEASE"),
    send_default_pii=False,
)

The SDK detects Django by itself. With Flask and FastAPI you add the same lines before you create the app. Locally you leave SENTRY_DSN empty, so nothing is sent.

4. Test it

def error_test(request):
    return 1 / 0

Map the view to a URL and call it. Within seconds the ZeroDivisionError shows up under Issues, with the URL and the view.

5. Celery and logging

If Celery is installed, the SDK also catches errors in tasks. Then also call sentry_sdk.init in your worker, for example in celery.py.

On top of that, every logger.error() becomes an error in errors.nl. Handy, but every stored error costs a credit. If your app logs a lot at error level, turn it off with the logging integration:

from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
    ...,
    integrations=[LoggingIntegration(event_level=None)],
)

6. Releases

Set SENTRY_RELEASE to your version or git commit on every deploy. Then you see in which release an error started, and a resolved error reopens when it comes back.

Personal data

With send_default_pii=False the SDK sends no IP addresses, cookies or the logged-in user. Local variables in the stack trace can still contain personal data; if you don't want to send them at all, set include_local_variables=False.

On top of that, errors.nl filters passwords, tokens, e-mail addresses and account numbers from every error before we store it. Read more in Error monitoring and the GDPR.

Notifications

Want to know when something goes wrong without keeping the dashboard open? Turn on e-mail notifications for your project, or connect Slack, Teams, Discord or ntfy for push notifications on your phone.

Start for free View the demo