Install our Python SDK using pip
:
$ pip install --upgrade sentry-sdk==0.9.0
Import and initialize the Sentry SDK early in your application’s setup:
import sentry_sdk
sentry_sdk.init("https://xxxxx@sentry.io/xxxx")
You can cause a Python error by inserting a divide by zero expression into your application:
division_by_zero = 1 / 0
The Django integration adds support for the Django Web Framework from Version 1.6 upwards.
Install sentry-sdk
:
$ pip install --upgrade 'sentry-sdk==0.13.2'
To configure the SDK, initialize it with the Django integration in your settings.py
file:
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn="https://xxxxxxxxxxxxxxxx@sentry.io/18xxxx",
integrations=[DjangoIntegration()]
)
You can easily verify your Sentry installation by creating a route that triggers an error:
from django.urls import path
def trigger_error(request):
division_by_zero = 1 / 0
urlpatterns = [
path('sentry-debug/', trigger_error),
# ...
]
Visiting this route will trigger an error that will be captured by Sentry.