Running with DEBUG=True can be painfully slow so I was switching back and forth when I needed to debug. I'm very happy with another solution; run the site without DEBUG, even in development and add this middleware to log the traceback. There are many benefits to this. Ever get a 500 on an ajax call? It's a little difficult to debug b/c django can't load a 500 page for you in that situation to see the traceback.
import logging, traceback
logger = logging.getLogger(__name__)
class ExceptionMiddleware(object):
def process_exception(self, request, exception):
logger.debug(traceback.format_exc())
return
Add this class to your MIDDLEWARE_CLASSES tuple (I think first is best) and you will be happy.
This is not recommended for public facing sites but have found it handy on an internal app. To give django's DEBUG error page when DEBUG=False:
from django.views.debug import ExceptionReporter
class ExceptionMiddleware(object):
def process_exception(self, request, exception):
tb = traceback.format_exc()
logger.debug(tb)
typ, val, trace = sys.exc_info()
if typ == Http404:
return
er = ExceptionReporter(request, *sys.exc_info())
return HttpResponseServerError(er.get_traceback_html())