Ticket #10863: 10863.diff

File 10863.diff, 2.5 KB (added by boxed, 6 years ago)
  • Users/boxed/django/django/core/handlers/base.py

     
    154154            return debug.technical_500_response(request, *exc_info)
    155155
    156156        # When DEBUG is False, send an error message to the admins.
     157        from django.views.debug import ExceptionReporter
     158        reporter = ExceptionReporter(request, *exc_info)
     159        html = reporter.get_traceback_html()
     160
    157161        subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
    158162        try:
    159163            request_repr = repr(request)
    160164        except:
    161165            request_repr = "Request repr() unavailable"
    162166        message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
    163         mail_admins(subject, message, fail_silently=True)
     167        mail_admins(subject, message, fail_silently=True, html_message=html)
    164168        # Return an HttpResponse that displays a friendly error message.
    165169        callback, param_dict = resolver.resolve500()
    166170        return callback(request, **param_dict)
  • Users/boxed/django/django/core/mail.py

     
    368368                for subject, message, sender, recipient in datatuple]
    369369    return connection.send_messages(messages)
    370370
    371 def mail_admins(subject, message, fail_silently=False):
     371def mail_admins(subject, message, fail_silently=False, html_message=None):
    372372    """Sends a message to the admins, as defined by the ADMINS setting."""
    373373    if not settings.ADMINS:
    374374        return
    375     EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
    376                  settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS]
    377                  ).send(fail_silently=fail_silently)
     375    from django.core.mail import EmailMultiAlternatives
     376    msg = EmailMultiAlternatives(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS])
     377    if html_message:
     378        msg.attach_alternative(html_message, "text/html")
     379    msg.send(fail_silently=fail_silently)
    378380
    379381def mail_managers(subject, message, fail_silently=False):
    380382    """Sends a message to the managers, as defined by the MANAGERS setting."""
Back to Top