79190646

Date: 2024-11-14 22:57:15
Score: 1
Natty:
Report link

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
Reasons:
  • Blacklisted phrase (0.5): i need
  • RegEx Blacklisted phrase (1): i want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Lord MooCow