Skip to content

Django Production Error Handler

2009 March 6
tags:
by pk

I am working on an application that, besides providing a dynamic website, also talks to an iPhone application. What happens when the iPhone, or a web visitor, triggered a bug in the application?

Django actually provide a nice mechanism to report error in its “batteries included” goodness. You can easily setup the Django environment so that it will send you an email when a “server error” occurs. You just need to make sure the following is setup:

Outbound email working

The django environment must be able to send outbound emails. The actual requirement depends on your server environment, but you definitely need to have correct values setup for:

settings.EMAIL_HOST
settings.EMAIL_PORT
settings.EMAIL_HOST_USER
settings.EMAIL_HOST_PASSWORD

Admin users

settings.ADMINS — this is a list of lists (or more accurately tuple of tuples)
settings.SERVER_EMAIL — email address of the error reporting from address
Debug Setup

settings.DEBUG=False

500.html and 404.html

Once DEBUG is off, Django will want to display your 500 or 404 page. Create these pages and make them available on one of our template directories.

Example

Here are some sample entries from my settings file:

EMAIL_HOST=’smtp.webfaction.com’
EMAIL_PORT=25
EMAIL_HOST_USER=’my_mailbox_name’
EMAIL_HOST_PASSWORD=’my_mailbox_password’
SERVER_EMAIL=’webmaster@imperial-consulting.com’
ADMINS=( (‘PK Shiu’, ‘support@imperial-consulting.com’),)
DEBUG=False

Reference

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Posterous
  • Tumblr
  • Twitter
3 Responses leave one →
  1. June 29, 2011

    have you seen django-sentry?

    http://blog.disqus.com/post/1178923988/django-sentry

  2. PK permalink*
    June 29, 2011

    Yeah. Sentry is a much bigger solution thought. For smaller apps the email admin “logger” is pretty useful. Note that for 1.3 the implementation has changed and the email admin option is now a proper python logging handler.

  3. July 1, 2011

    Yeah I’d have to agree with @fisadev. As a developer I can’t see a project where I wouldn’t enable sentry. The email error logger and anything else is vastly inferior.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS