'How do I get Sentry reference ID in html template using sentry-sdk?

Since the raven is deprecated I need an alternative way to display Sentry reference ID in my html template.

The previous version looks like this from the example:

<p>You've encountered an error, oh noes!</p>
{% if request.sentry.id %}
<p>
  If you need assistance, you may reference this error as
  <strong>{{ request.sentry.id }}</strong>.
</p>
{% endif %}

How do I do this now? I tried to use sentry_sdk.capture_exception() or sentry_sdk.last_event_id() method. The first one returns None in my template, the second one looks like it's now what I am looking for.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source