We are developing a project with several applications using Django. It shares the database, but it has several applications targeting different very different users. Roughly, administrators and final users. The UI of each application is very different. I need to create a 404 error page, but seems that I can only create one for all the project. I would like to create different 404 templates and being able to shown them depending on the application (URL) the user is asking for...
For general, clearly invalid URL it's easy, but in the code there are other ways of launching exceptions, like get_object_or_404
calls.
Anyone knows a way of doing that?
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
It's not at all true that you can only create a single 404 page for the entire app. The documentation explains how you can create a specific 404 handler view, which of course can look at the value of request.path
to see what URL was requested and render the relevant template.
Write a 404 view by setting handler404
, and not just a template. In that view, try to figure from the url which 404 you should show, and render that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With