This would be an alternative way to solve the question on SO, without using the contrib.message framework.
Make it possible to use Exception details on custom 404 handlers.
This would be an alternative way to solve the question on SO, without using the ``contrib.message`` framework.
I'm not completely convinced this is a good idea. Django's built in views generate a number of 404 exceptions with messages which are definitely not designed to be displayed to an end user. If you want a custom message, I think messages is the right way to go.
I'm not going to close this though as other people may feel differently. Please do open a ticket on trac. This patch would also need a test case.
Thanks for leaving it open.
Worth saying that passing the argument the view doesn't mean that it is going to be used in the template itself. Actually, the reason for doing this, is to make it possible to track, even in an production environment, what detaild of the Http404 error users are getting, once this information is already available.
I'll open the ticked, as you said.
Thank you very much for being willing to help out a Django user on SO, and taking the time to consider contributing an improvement back to Django. In the end I feel this is a misuse of the 404 exception.
At the time you would raise any 404 exception, you have the request object. You can always used this to pass custom data to your custom 404 handler.
But really 404 has a very narrow HTTP meaning. If you have messages that relate to something in your application, you should be considering a custom error view, or a view hierarchy that catches your own exception classes as needed.
You can also add custom logging for reasons you are hitting some issue, and use those for your analysis rather than putting that into your handler.