You catch the exception in an exception variable:
# some code
except Exception, e:
# Log the exception.
There are various ways to format the exception, the logging module (which I assume you/Django uses) has support to format exceptions, and the exceptions themselves usually render useful messages when rendered to strings.
Here is an example:
logging.debug('This message should go to the log file')
except Exception as e:
This example uses the new "as" syntax to catch the exception, supported in Python 2.6 and later. The output of the above is:
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>
ZeroDivisionError: integer division or modulo by zero