Django 500 Error Patch

154 views
Skip to first unread message

Adam Solesby

unread,
Nov 4, 2008, 10:31:35 PM11/4/08
to Django Nashville
Django's default rich HTML error message is not ideal for ajax calls.
There are many ways to solve this, but I like to use this simple patch
to the django source. This modifies technical_500_response() to output
the exception details and stack trace to the console.

$ svn diff django/views/debug.py
Index: django/views/debug.py
===================================================================
--- django/views/debug.py (revision 9240)
+++ django/views/debug.py (working copy)
@@ -37,6 +37,16 @@
"""
reporter = ExceptionReporter(request, exc_type, exc_value, tb)
html = reporter.get_traceback_html()
+
+ ## added by ad...@studionow.com
+ print '-' * 80
+ print ' 500 Exception', reporter.exc_type, reporter.exc_value
+ print ' url:', request.path, '\n'
+ frames = reporter.get_traceback_frames()
+ for fr in [ frames[i] for i in range( len(frames)-1, 0, -1 ) ]:
+ print ' trace: [%5s] %-20s in %s' % (fr['lineno'] ,
fr['function'], fr['filename'] )
+ print '-' * 80
+
return HttpResponseServerError(html, mimetype='text/html')

class ExceptionReporter:


Reply all
Reply to author
Forward
0 new messages