I think you can achieve this by writing a decorator.
The decorator should catch ApiServerNotRespond
or any other exception you want. And if such exception occurs return response with template you want otherwise just return response from the original view.
Sample:
def custom_error_handler():
def decorator(orig_func):
def inner_func(request, *args, **kwargs):
try:
return orig_func(request, *args, **kwargs)
except ApiServerNotRespond:
context = {}
return render_to_response('custom_template.html', context
context_instance = RequestContext(request))
except Exception:
#handle all other errors, may be just raise
raise
return wraps(orig_func)(inner_func)
return decorator
In your views.py,
@custom_error_handler
def sample_view1(request):
#your code