[Answered ]-How to link django to my own 404 error page?

2πŸ‘

βœ…

In order to show customized HTML when Django returns a 404, you can create an HTML template named 404.html and place it in the top level of your template tree. This template will then be served when DEBUG is set to False.

https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view

Also, there is an useful section β€œCustomizing error views”.

And in the case you want to test your template withour turning DEBUG=False, you can run manage.py runserver --insecure.
It will force Django to serving static files with the staticfiles app even if the DEBUG setting is False. But note that it it only for local development and could be insecure. You can read more about this option here.

πŸ‘€Paul

0πŸ‘

Here is a quote from the Django doc:

This template should be called 404.html and located in the top level of your template tree.

Check here for the full text; for non 1.8 doc it should be somewhere around here: Writing views > Returning errors > The Http404 exception.

0πŸ‘

You should create following view:

def custom404(request):
    return render(request, '404.html', status=404)

And connect it with following construction in urls.py:

handler404 = 'path.to.views.custom404'
πŸ‘€Dracontis

Leave a comment