How to make django specific error message to print 500

C:\Python27\Lib\site-packages\django\core\handlers\base.py
 
Add a piece of code in this file base.py
def handle_uncaught_exception(self, request, resolver, exc_info):
"""
Processing for any otherwise uncaught exceptions (those that will
generate HTTP 500 responses). Can be overridden by subclasses who want
customised 500 handling.
 
Be *very* careful when overriding this because the error could be
caused by anything, so assuming something like the database is always
available would be an error.
"""
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
 
logger.error('Internal Server Error: %s', request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request': request
}
)
 
# After adding this code, you can print out
#===========Code start =======by chang
print "------HTTP 500 Error Msg"
print exc_info
import traceback
print traceback.format_exc()
print "------------------------"
#============Code end================
 
if settings.DEBUG:
return debug.technical_500_response(request, *exc_info)
 
# If Http500 handler is not installed, re-raise last exception
if resolver.urlconf_module is None:
six.reraise(*exc_info)
# Return an HttpResponse that displays a friendly error message.
callback, param_dict = resolver.resolve_error_handler(500)
return callback(request, **param_dict)

Guess you like

Origin www.cnblogs.com/leo6099/p/11836732.html