tags:

views:

792

answers:

4

It is running under DEBUG = True mode. Sometimes it can throw out an error message with traceback information when encounter an error but sometimes it just display the following lines:

Unhandled Exception

An unhandled exception was thrown by the application.

I have to switch to development server to see detail message.

How can I make it always display traceback message when an error is encountered?

+1  A: 

That's what DEBUG=True is for: to show the full traceback. The idea is that regular users do not want (nor do you want them to) see anything other than a simple error message.

Matthew Schinckel
There are certain errors that occur outside the 500-debug-page handling, where you still get a raw error from the webserver.
Carl Meyer
Yep, I've noticed too that sometimes I get mod_python error pages rather than the Django page.
Alex JL
+1  A: 

Are you using Apache?
Just out of interest is this your Production or Dev environment where you want to see the traceback?

From the DJango Book on security - Exposed error messages

Users deploying under Apache and mod_python should also make sure they have PythonDebug Off in their Apache conf files; this will ensure that any errors that occur before Django’s had a chance to load won’t be displayed publicly.

I assume you want PythonDebug On, this is recommended for Development only.

Ralph Willgoss
@Ralph, I'm using Nginx.
jack
i'm using mod_python with PythonDebug Off and i can still switch DEBUG = True in my settings to quickly troubleshoot an issue. It still gives me the handy django debug page instead of apache's 500 internal server error page.
Brandon H
sorry Jack, haven't used Nginx, so maybe someone with Nginx might be able to help trouble shoot. Brandon - could this be a Nginx specific?
Ralph Willgoss
+2  A: 

Maybe you can use this snippet, this will log exceptions in apache's log:

utils.py:

def log_traceback(exception, args):
    import sys, traceback, logging
    exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
    logging.debug(exception)
    logging.debug(args)
    for tb in traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback):
        logging.debug(tb)

site_logging.py:

import logging
import sys

logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

Put it in your settings.py :

import site_logging

And in your code:

from where.is.your.utils import log_traceback
try:
   `do something`
except Exception, args
    log_traceback(Exception, args)
diegueus9
A: 

I have an exactly similar situation sometime in the past and I have blogged about it also. And I came up with trying multiple options along with this. It solved my purpose, I advice you also try running imports_checker

Maddy