python - Django - catch exception -


it might python newbie question...

try:    #do except:    raise exception('xyz has gone wrong...') 

even debug=true, don't want raise exception gives me yellow page. want handle exception redirecting users error page or shows error (give css error message on top of page...)

how handle that? can guide me? if raise it, yellow debug page (again, don't want exceptions stop site functioning showing debug page when debug=true).

how handle these exceptions in views.py?

thanks.

you have 3 options here.

  1. provide 404 handler or 500 handler
  2. catch exception elsewhere in code , appropriate redirection
  3. provide custom middleware process_exception implemented

middleware example:

class myexceptionmiddleware(object):     def process_exception(self, request, exception):         if not isinstance(exception, someexceptiontype):             return none         return httpresponse('some message') 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -