Skip to content

Make it possible to use Exception details on custom 404 handlers. #1397

Closed
wants to merge 1 commit into from

3 participants

@femesq
femesq commented Jul 25, 2013

This would be an alternative way to solve the question on SO, without using the contrib.message framework.
http://stackoverflow.com/questions/1621173/404-error-messages-in-django

@femesq femesq 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.
``
http://stackoverflow.com/questions/1621173/404-error-messages-in-django
``
b1b0307
@mjtamlyn
Django member

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.

@femesq
femesq commented Jul 25, 2013

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.

@ptone
Django member
ptone commented Aug 15, 2013

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.

@ptone ptone closed this Aug 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.