Can you have more than one application manage a 404 in Django?

advertisements

Apparently, the way Django flatpages works is that it handles the 404 thrown by other apps. I was wondering if I could do another flatpages-type app that gets a crack at the 404 before flatpages does. I tried this without success so far. A template gets rendered but the data doesn't come through.

Is it even possible?


As per the Django docs, you can specify your own view as a 404 or 500 handler:

handler404 = 'mysite.views.my_custom_404_view'

So, your app can define a custom error handling view in views.py that you can setup as the handler for 404 or 500 view in your urls.py

See "Customizing Error views" for more info.