I’m new to Django and have some code in my views.py like this:
try:
myfunction()
except:
assert False, sys.exc_info()[0]
This is very helpful because I get an email with lots of useful info if there’s an error.
The problem is that it also redirects the user to a Webfaction system error page. What I’d like to know is how do I still get the useful error email, but redirect the user to my own error page?
Also, is this the best way to be handling errors in Django?
This is wrong on quite a few levels.
Firstly, there is no reason to catch an exception only to raise another one. If your application raises an exception, then Django’s own middleware will catch it, and depending on whether or not you have
DEBUG=True, either show a detailed debugging page, or mail the exception to the users mentioned in theADMINSsetting.Secondly, you should never be getting a Webfaction error page – I can’t even imagine how that is happening. If you want your users to see a nice error page, you should define 404.html and 500.html templates, or even full error-handling views if your needs are more complicated. This is fully explained in the documentation.