Last modified: December 18, 2020

Django HttpResponseGone: Return no Longer Available Response

HttpResponseGone: is a subclass of HttpResponse that returns an HTTP response with 410 status.

410 status code: access to the target resource is no longer available at the origin server and that this condition is likely to be permanent.

However, if you're not sure that a view or task not available for permanent, you should use 404 response.


1. Django HttpResponseGone with example

To understand how HttpResponseNotAllowed is working, let's write a simple example:

first, we need to import HttpResponseGone by the following line:

from django.http import HttpResponseGone


example:

def page_not_av(request):
    return HttpResponseGone('<h1>This Page is Not Longer Available.</h1>')


result:

Django HttpResponseGone: return no Longer Available Response

response's status:

Django HttpResponseGone: return no Longer Available Response

3. How to solve HttpResponseGone is not defined

issue's output:

Django HttpResponseGone: return no Longer Available Response

To solve this issue, you simply need to import the subclass before your view like:

from django.http import HttpResponseGone