1

While in development, I managed to redirect traceback messages (which by default appeared in the local console) to the client's browser console with some custom middleware.

However, when doing this, the traceback no longer displays in the console. Is there a way to have it both in the local console, and in the client's browser?

The middelware used (based on solutions from here and here):

import traceback 
from django.http import HttpResponse

class ErrorMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        return self.get_response(request)

    def process_exception(self, request, exception):
        tb = traceback.format_exc()
        return HttpResponse(tb)
sc28
  • 1,163
  • 4
  • 26
  • 48

1 Answers1

0

Returning an HttpResponse from process_exception will cause other middleware.process_exception to not be run.

https://docs.djangoproject.com/en/3.0/topics/http/middleware/#process-template-response

By default, if DEBUG = True, then stack traces should show in both the dev server console and in the browser.

Airith
  • 2,024
  • 1
  • 14
  • 10