Django spróbuj złapania wyjątku

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')
Defeated Dogfish