Code Execution for Django 404 Custom Page

I'm going to deploy my first Django application and put a little pressure on the checkpoint. My basic template relies on passing a session object so that it can read the current username. This is not a problem when I control the code that invokes the template.

However, as part of this deployment-ready application, I need to create a 404.html page. I have expanded the base template in the same way as my other pages, but I see no way to pass the session object so that I can use it. Is there a way for Django to call its own method to render your 404, and not just your 404.html for you?

+6
python django
source share
2 answers

You need to override the default view handler for error 404. Here is the documentation on how to create your own 404 view function:

http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views

+11
source share

Define your own 404 handler. See Django URLs , specifically the handler404 part.

+3
source share

All Articles