hata raporlama görünür, ve tabii ki hata e-postaların kontrolleri ne django debug view yılında TECHNICAL_500_TEMPLATE
/TECHNICAL_500_TEXT_TEMPLATE
değişken bir Django şablon var. Bir yorum, şablonun bir python değişkeninde olduğunu ve böylece şablon yükleyicinin kırılması durumunda hataların oluşturulabileceğini açıklar. Bu değişkeni django paketinizde değiştirebilirsin ama bunu önermiyorum. TECHNICAL_500_TEMPLATE
, aynı dosyada ExceptionReporter
sınıfı tarafından başvurulan.
django utils logAdminEmailHandler
sınıfında, html hata raporu oluşturmak için ExceptionReporter
kullanılır.
Sen AdminEmailHandler
alt sınıf ve kendi TECHNICAL_500_TEMPLATE
tanımlanan kullanır ExceptionReporter
sizin Subclassed versiyonunu içerecek şekilde emit
işlevini geçersiz kılabilir.
İşte bir örnek:
sadece logging section da yeni bir işleyici kullanmak üzere django ayarlarını ardından
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)
ile reporter.py
oluşturma Ve. Eğer geçersiz kılmak ve CustomExceptionReporter
macunu
def get_traceback_data(self):
kopyalarsanızsadece sen
burada benziyordu: [https: //docs.djangoproject. com/es/1.9/howto/error-raporlama/# filtreleme duyarlı bilgi] (https://docs.djangoproject.com/es/1.9/howto/error-reporting/#filtering-sensitive-information) – niklas'settings': get_safe_settings(),
hattını 294 üzerinden yorum yapabilirsiniz ayarlarını gizlemek istiyorsanızAyrıca, sizin için perspektif içine bir şeyler koymak: https://docs.djangoproject.com/en/1.9/ref/settings/#debug - API, TOKEN, ANAHTAR, GİZLİ, PASS veya İMZA içeren tüm belirteçleri otomatik olarak gizleyecektir – karthikr
Iki que var Sizinkiyle benzer bulduğum stiller: http://stackoverflow.com/questions/27411362/django-error-reporting-emails-env-vars-leak-info ve http://stackoverflow.com/questions/12301105/django- @niklas'ın ne dediğine yol açan 1-3 hata-raporu-remove-sensitive-information? Rq = 1. –