try:
    response.render()
except ImmediateHttpResponse as e:
    return HttpResponseRedirect(e.response)
return response
Django: How to catch a specific exception in a class based view during template rendering?