You catch the exception in the exception variable:
try:
There are various ways to format exceptions, the logging module (which I assume you / Django uses) has support for formatting exceptions, and the exceptions themselves usually provide useful messages when rendering strings.
Here is an example:
import logging logging.basicConfig(level=logging.DEBUG) logging.debug('This message should go to the log file') try: 1/0 except Exception as e: logging.exception(e)
This example uses the new "how" syntax to throw an exception that is supported in Python 2.6 and later. The output is higher:
DEBUG:root:This message should go to the log file ERROR:root:integer division or modulo by zero Traceback (most recent call last): File "untitled-1.py", line 6, in <module> 1/0 ZeroDivisionError: integer division or modulo by zero
Lennart Regebro
source share