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.
- provide 404 handler or 500 handler
- catch exception elsewhere in code , appropriate redirection
- provide custom middleware
process_exceptionimplemented
middleware example:
class myexceptionmiddleware(object): def process_exception(self, request, exception): if not isinstance(exception, someexceptiontype): return none return httpresponse('some message')
Comments
Post a Comment