Custom error reports.

Is there a way in which the information from error pages can be passed to the next request object ? For example, if you try to do 1/0 operation, Django displays it’s usual error page (Zero division error) if DEBUG is True. What I’d like to do is instead display that information in a bootstrap modal.

I have gone through custom error reports here Error reporting | Django documentation | Django but without a concrete example, it’s hard to follow.

Any help is appreciated !

What I think you’re looking for is The messages framework.

From the second paragraph in the docs:

The messages framework allows you to temporarily store messages in one request and retrieve them for display in a subsequent request (usually the next one).

After digging a bit more, it is this that I was after actually Built-in Views | Django documentation | Django
To customize the 500 server error view, such that when an exception occurs, the trace back data can be displayed in a modal (from a custom template). The only problem is that it happens to be a custom view and hence, the page on which the modal is displayed is gone (understandable since I don’t know what view will be there when the exception occurs). Any ideas on how that could be circumvented ?

Ok, I didn’t pick up that that was what you were trying to do.

A 500 error almost always implies that something has gone fundamentally wrong internally, preventing the normal request/response cycle from completing. Since those types of errors are generally caused by something in the view, you won’t know / can’t rely upon knowing what the original response was going to be - or rely upon the data that would have been necessary to generate that view.

About the best you can do would be to return to some base state, such as a “home page” - but even that’s dependent upon the internal state of the session being sufficiently consistent to reliably render it.

1 Like