Django - catch exception

前端 未结 4 488
灰色年华
灰色年华 2021-01-11 17:32

It might be a Python newbie question...

try:
   #do something
except:
   raise Exception(\'XYZ has gone wrong...\')

Even with DEBUG=True,

4条回答
  •  日久生厌
    2021-01-11 18:15

    You can raise a 404 error or simply redirect user onto your custom error page with error message

    from django.http import Http404
    #...
    def your_view(request)
        #...
        try:
            #... do something
        except:
            raise Http404
            #or
            return redirect('your-custom-error-view-name', error='error messsage')
    
    1. Django 404 error
    2. Django redirect

提交回复
热议问题