There are probably several ways to land this, but below is what I do. While there could be some optimization to this, it works well so long as the error is within the django app and not with the webserver itself.
in urls.py: (don't see any difference here).
if not DEBUG: # i don't want custom error handling in my dev environment because i want to see the dump to help with troubleshooting.
handler500 = '<project>.views.custom_500'
in views.py: I see some differences here... don't know if they are necessarily material or not.
def custom_500(request, *args, **argv):
context = {'<load up the data i need to send to the custom template>',}
t = loader.get_template('error.html')
response = HttpResponseServerError(t.render(context))
response.status_code = 500 # need to set this to ensure flags the error and sends dump data to admins.
return response