Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Unhandled Exception

Tags:

python

django

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?

like image 426
jack Avatar asked Dec 18 '09 02:12

jack


2 Answers

Just connect to the got_request_exception signal and log the exception:

from django.core.signals import got_request_exception
import logging    

def log(*args, **kwargs):
    logging.exception('error')

got_request_exception.connect(log)

This will log the whole trace. In the dev server, it logs in the console.

like image 116
stephane k. Avatar answered Oct 08 '22 10:10

stephane k.


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.

like image 41
Ralph Willgoss Avatar answered Oct 08 '22 09:10

Ralph Willgoss