I\'d like to return 410 errors at for some of my Django pages instead of returning 404s. Basically, instead of calling raise Http404(\'some error message\')
, I woul
Return a HttpResponseGone
, a subclass of HttpResponse, in your view handler.
from django.http import HttpResponse
return HttpResponse(status=410)
Django does not include a mechanism for this because gone should be normal workflow, not an error condition, but if you want to not treat it as a return response, and as an exception, just implement a middleware.
class MyGoneMiddleware(object):
def process_exception(self, request, exception):
if isinstance(exception, Http410):
return HttpResponseGone("Gone!")
return None