def dispatch(self, *args, **kwargs):
    response = super(AppConnectionsView, self).dispatch(*args, **kwargs)
try:
    response.render()
except ImmediateHttpResponse as e:
    return HttpResponseRedirect(e.response)
Django: How to catch a specific exception in a class based view during template rendering?