TECHNICAL_500_TEMPLATE
/TECHNICAL_500_TEXT_TEMPLATE
がdjango debug viewにあります。この変数は、エラー報告に表示される内容やエラーメールを制御します。コメントは、テンプレートローダーが壊れた場合にエラーが生成されるように、テンプレートがPython変数にあることを説明しています。あなたはあなたのdjangoパッケージでこの変数を変更することができますが、私はそれをお勧めしません。 TECHNICAL_500_TEMPLATE
は、同じファイル内のExceptionReporter
クラスによって参照されます。
AdminEmailHandler
のdjango utils logは、ExceptionReporter
を使用してhtmlエラーレポートを生成します。
あなたはAdminEmailHandler
をサブクラス化し、独自のTECHNICAL_500_TEMPLATE
を定義し使用していますExceptionReporter
のあなたのサブクラス化バージョンを含めるようにemit
関数をオーバーライドすることができます。
はここに例を示します
は
from copy import copy
from django.views import debug
from django.utils import log
from django.conf import settings
from django import template
TECHNICAL_500_TEMPLATE = """
# custom template here, copy the original and make adjustments
"""
TECHNICAL_500_TEXT_TEMPLATE = """
# custom template here, copy the original and make adjustments
"""
class CustomExceptionReporter(debug.ExceptionReporter):
def get_traceback_html(self):
t = debug.DEBUG_ENGINE.from_string(TECHNICAL_500_TEMPLATE)
c = template.Context(self.get_traceback_data(), use_l10n=False)
return t.render(c)
def get_traceback_text(self):
t = debug.DEBUG_ENGINE.from_string(TECHNICAL_500_TEXT_TEMPLATE)
c = template.Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
return t.render(c)
class CustomAdminEmailHandler(log.AdminEmailHandler):
def emit(self, record):
try:
request = record.request
subject = '%s (%s IP): %s' % (
record.levelname,
('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
else 'EXTERNAL'),
record.getMessage()
)
except Exception:
subject = '%s: %s' % (
record.levelname,
record.getMessage()
)
request = None
subject = self.format_subject(subject)
no_exc_record = copy(record)
no_exc_record.exc_info = None
no_exc_record.exc_text = None
if record.exc_info:
exc_info = record.exc_info
else:
exc_info = (None, record.getMessage(), None)
reporter = CustomExceptionReporter(request, is_email=True, *exc_info)
message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())
html_message = reporter.get_traceback_html() if self.include_html else None
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
でreporter.py
を作成してからちょうどlogging sectionに新しいハンドラを使用するようにDjangoの設定を行います。
LOGGING = {
# Your other logging settings
# ...
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'project.reporter.CustomAdminEmailHandler',
'filters': ['special']
}
},
}
あなたはちょうどあなたがオーバーライドしてCustomExceptionReporter
で
def get_traceback_data(self):
を貼り付けコピーした場合、あなたがここを見てなかった、あなたは'settings': get_safe_settings(),
ライン294をコメントアウトすることができます設定を非表示にする場合:[HTTPS://docs.djangoproject。 com/es/1.9/howto /エラー報告/#フィルタに敏感な情報](https://docs.djangoproject.com/es/1.9/howto/error-reporting/#filtering- sensitive-information) – niklasまた、あなたのために物事をあなたのために置く:https://docs.djangoproject.com/ja/1.9/ref/settings/#debug - API、TOKEN、KEY、SECRET、PASS、またはSIGNATUREを含むすべてのトークンが自動的に隠される – karthikr
2つのキューがありますあなたと同じように私が見つけたstions:http://stackoverflow.com/questions/27411362/django-error-reporting-emails-env-vars-leak-info and http://stackoverflow.com/questions/12301105/django- 1-3エラーレポートの削除に敏感な情報?rq = 1これは@niklasの説明につながります。 –