Star us on GitHub

Using with Python Django

Learn how to set up on your Python Django backend API.
Setup your frontend Highlight snippet with tracingOrigins.

Make sure that you followed the fullstack mapping guide.

H.init("<YOUR_PROJECT_ID>", { tracingOrigins: ['localhost', ''], networkRecording: { enabled: true, recordHeadersAndBody: true, }, });
Install the highlight-io python package.

Download the package from pypi and save it to your requirements. If you use a zip or s3 file upload to publish your function, you will want to make sure highlight-io is part of the build.

poetry add highlight-io[Django]
# or with pip pip install highlight-io[Django]
Initialize the Highlight SDK.

Add Highlight with the Django integration to your file.

import highlight_io from highlight_io.integrations.django import DjangoIntegration # `instrument_logging=True` sets up logging instrumentation. # if you do not want to send logs or are using `loguru`, pass `instrument_logging=False` H = highlight_io.H( "<YOUR_PROJECT_ID>", integrations=[DjangoIntegration()], instrument_logging=True, service_name="my-django-app", service_version="git-sha", environment="production", )
Verify your installation.

Check that your installation is valid by throwing an error. Change one of your Django views to the following code which will throw an exception. Access the Django route in your browser. You should see a DivideByZero error in the Highlight errors page within a few moments.

import logging import random from django.http import HttpResponse, HttpRequest def index(request: HttpRequest): return HttpResponse(f"This might not go well. result is {2 / 0}")
Set up logging.

With the Python SDK, your logs are reported automatically from builtin logging methods. See the Python logging setup guide for more details.