python - Manually trigger Django email error report -


django error reporting handles uncaught exceptions sending email, , (optionally) shows user nice 500 error page.

this works well, in few instances i'd allow users continue business uninterrupted, still have django send me email error report exception.

so basically: can manually send email error report if catch exception?

of course, i'd avoid manually generating error report email.

you can use following code send manually email request , exception e:

import sys import traceback django.core import mail django.views.debug import exceptionreporter  def send_manually_exception_email(request, e):     exc_info = sys.exc_info()     reporter = exceptionreporter(request, is_email=true, *exc_info)     subject = e.message.replace('\n', '\\n').replace('\r', '\\r')[:989]     message = "%s\n\n%s" % (         '\n'.join(traceback.format_exception(*exc_info)),         reporter.filter.get_request_repr(request)     )     mail.mail_admins(         subject, message, fail_silently=true,         html_message=reporter.get_traceback_html()     ) 

you can test in view this:

def test_view(request):     try:         raise exception     except exception e:         send_manually_exception_email(request, e) 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -