[Django]-Hide Django settings value (for Celery) on error page

3๐Ÿ‘

I know this is old, but I wanted to post an answer since I came across this question when I was researching a similar problem. OP was on the right track about about filtering error reports. I hope this helps someone!

import re
from django.views.debug import SafeExceptionReporterFilter

# These are the default patterns Django will match as of 4.2
HIDDEN_DEFAULT = 'API|TOKEN|KEY|SECRET|PASS|SIGNATURE|HTTP_COOKIE|'
EXTRA = 'CELERY|SOME_OTHER_KEY'

class CustomExceptionReporterFilter(SafeExceptionReporterFilter):

    def __init__(self):
        super().__init__()
        self.hidden_settings = re.compile(
            pattern=f'{HIDDEN_DEFAULT}{EXTRA}',
            flags=re.IGNORECASE
        )

Then add this to your settings.py file:

DEFAULT_EXCEPTION_REPORTER_FILTER = "path.to.module.CustomExceptionReporterFilter"

Here is some additional information on custom error reporting in the Django docs: https://docs.djangoproject.com/en/4.2/howto/error-reporting/#custom-error-reports

๐Ÿ‘คChad

Leave a comment