catherine
catherine

Reputation: 22808

How to catch all the errors in all views?

I know we can use try and except function to catch the error. But everyday I monitor the sentry, the system always get an exception in any views. As usual I put try and except to catch the errors in the views.

My question is. Is it possible to catch all the errors from any views in just one function? Then the user will redirect to another page. Where is the best place to do this? I'm thinking about middleware but I don't have knowledge about it.

Upvotes: 2

Views: 254

Answers (1)

Vincent Wen
Vincent Wen

Reputation: 1852

yes, can handle all exceptions from any view. try Googling "django middleware exception", you'll find many solutions .

Upvotes: 5

Related Questions