import traceback
import sys
try:
    raise Exception('Message')
except:
    type, value, tb = sys.exc_info()
print(type.__name__, ':', value, file=sys.stderr)
How do I include a stacktrace in my Django 500.html page?