How do I include a stacktrace in my Django 500.html page?

I'm running Django 1.0 and I'm close to deploying my app. As such, I'll be changing the DEBUG setting to False.

With that being said, I'd still like to include the stacktrace on my 500.html page when errors occur. By doing so, users can copy-and-paste the errors and easily email them to the developers.

Any thoughts on how best to approach this issue?


Automatically log your 500s, that way:

  • You know when they occur.
  • You don't need to rely on users sending you stacktraces.

Joel recommends even going so far as automatically creating tickets in your bug tracker when your application experiences a failure. Personally, I create a (private) RSS feed with the stacktraces, urls, etc. that the developers can subscribe to.

Showing stack traces to your users on the other hand could possibly leak information that malicious users could use to attack your site. Overly detailed error messages are one of the classic stepping stones to SQL injection attacks.

Edit (added code sample to capture traceback):

You can get the exception information from the sys.exc_info call. While formatting the traceback for display comes from the traceback module:

import traceback
import sys

	raise Exception("Message")
	type, value, tb = sys.exc_info()
	print >> sys.stderr,  type.__name__, ":", value
	print >> sys.stderr, '\n'.join(traceback.format_tb(tb))


Exception : Message
  File "", line 5, in <module>
    raise Exception("Message")

Need Your Help

Why does SubItems.Clear() also delete the Name attribute?

c# .net winforms listview listviewitem

I am using a WinForms ListView in details mode (.NET 4.0, running on Windows 7) and I have a function that needs to clear the subitems in a particular item. Unfortunately when I do that it also cl...

PHP Email on redirect

php email

I have a page on my website that only certain users can access, and for that I made a check that looks into the MySQL database to see if they fulfill the requirements or not, and if they don't then...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.