0

I have a system that has deployed django-hosts, all is working fine. Until now I have been handling 404 and 500 errors for production by utilizing the neat trick of just placing files 500.html and 404.html in the root of the templates folder. This very nicely handles these errors in production (debug=False).

However, now I want to get a little more creative with my error handling messaging and feedback to the user. I have other projects where I have created a custom view for the error handling.

e.g.

def custom_error_500(request, exception=None):

    print ('error 500 ') #For debugging to verify view is being processed.
    return render(request, "errors/500.html", status=500)

and then set this parameter at the bottom of the urls.py (appname is 'main')

handler500 = 'main.errorviews.custom_error_500'

This all works very nicely in a project that does NOT use django-hosts. The advantage of creating the custom view is that the context is past to the RequestContext to the template, whereas by default not the case (see reference).

Now, I know with django-hosts here is magic going on in the way urls.py are processed for each host. Could this be the reason why?. I tried placing the hander500 setting in all the possible urls.py that I have in project, but I get the same result, which is the system just looks for the 500.html in the root and if it does not find it displays the standard built in Server Error 500 message.

Has anyone else had the same problem? I can not believe I am the only one trying to display a customer error message using django hosts :-).

Thanks in advance for any assistance!

Paul West
  • 81
  • 8

0 Answers0