Reporting HTTP Errors
If you want to report 404 Not Found
and other errors besides uncaught exceptions (500 Internal Server Error
) to Sentry, you can write your own Django view for those status codes. For example:
Copied
# urls.py
handler404 = 'mysite.views.my_custom_page_not_found_view'
# views.py
from django.http import HttpResponseNotFound
from sentry_sdk import capture_message
def my_custom_page_not_found_view(*args, **kwargs):
capture_message("Page not found!", level="error")
# return any response here, e.g.:
return HttpResponseNotFound("Not found")
The error message you send to Sentry will have the usual request data attached.
For details about capture_message()
, see the API Documentation.
Refer to Customizing Error Views from the Django documentation for more information. You can also view our troubleshooting information.
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- pypi:sentry-sdk
- Version:
- 2.0.0
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/