The default error views in Django should suffice for most Web applications, but can easily be overridden if you need any custom behavior. Specify the handlers as seen below in your URLconf (setting them anywhere else will have no effect).

The page_not_found() view is overridden by handler404:

define this path in your project main file before urlpatterns

handler404 = 'mysite.views.handler404'

And now go to your file and add this code…

def handler404(request, exception):
    return render(request, 'errors/404.html', status=404)

Similarly Other Error Code…

The server_error() view is overridden by handler500:

handler500 = 'mysite.views.my_custom_error_view'

The permission_denied() view is overridden by handler403:

handler403 = 'mysite.views.my_custom_permission_denied_view'

The bad_request() view is overridden by handler400:

handler400 = 'mysite.views.my_custom_bad_request_view'

Documentation: Django 404 Error


Please enter your comment!
Please enter your name here