- March 19, 2008
- 14 (after 14 ratings)
When debugging AJAX with Firebug, if a response is 500, it is a pain to have to view the entire source of the pretty exception page. This is a simple middleware that just returns the exception without any markup. You can add this anywhere in your python path and then put it in you settings file. It will only unprettify your exceptions when there is a XMLHttpRequest header. Tested in FF2 with the YUI XHR. Comments welcome.
EDIT: I recently changed the request checking to use the is_ajax() method. This gives you access to these simple exceptions for get requests as well (even though you could just point your browser there).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from django.conf import settings from django.http import HttpResponseServerError class AJAXSimpleExceptionResponse: def process_exception(self, request, exception): if settings.DEBUG: if request.is_ajax(): import sys, traceback (exc_type, exc_info, tb) = sys.exc_info() response = "%s\n" % exc_type.__name__ response += "%s\n\n" % exc_info response += "TRACEBACK:\n" for tb in traceback.format_tb(tb): response += "%s\n" % tb return HttpResponseServerError(response)
More like this
- A wrapper around cache_page making it optional by rixx 6 days ago
- Treat empty value on DateRangeFilter as a filter for non filled dates by kmmbvnr 1 month, 2 weeks ago
- Django Settings Assignment Expressions aka Walrus Operator example by webology 2 months, 2 weeks ago
- codigo alto nivel by MrRocklion 4 months, 1 week ago
- Load template from specific app by Krzysiek555 5 months ago