Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #9430 -- Fixed documentation references to the HttpResponse cla…

…sses for

returning HTTP status codes other than 200.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cbe11c1982b5519171a8caae6f99629899dc929b 1 parent 2f87035
@malcolmt malcolmt authored
Showing with 21 additions and 5 deletions.
  1. +2 −0  docs/ref/request-response.txt
  2. +19 −5 docs/topics/http/views.txt
2  docs/ref/request-response.txt
@@ -525,6 +525,8 @@ Methods
.. _HTTP Status code:
+.. _ref-httpresponse-subclasses:
HttpResponse subclasses
24 docs/topics/http/views.txt
@@ -64,11 +64,13 @@ date and time. To display this view at a particular URL, you'll need to create a
Returning errors
-Returning HTTP error codes in Django is easy. We've already mentioned the
-:class:`HttpResponseNotFound`, :class:`HttpResponseForbidden`,
-:class:`HttpResponseServerError`, etc., subclasses; just return an instance of one
-of those subclasses instead of a normal :class:`HttpResponse` in order to signify
-an error. For example::
+Returning HTTP error codes in Django is easy. There are subclasses of
+:class:`~django.http.HttpResponse` for a number of common HTTP status codes
+other than 200 (which means *"OK"*). You can find the full list of available
+subclasses in the :ref:`request/response <ref-httpresponse-subclasses>`
+documentation. Just return an instance of one of those subclasses instead of
+a normal :class:`~django.http.HttpResponse` in order to signify an error. For
def my_view(request):
# ...
@@ -77,6 +79,18 @@ an error. For example::
return HttpResponse('<h1>Page was found</h1>')
+There isn't a specialized subclass for every possible HTTP response code,
+since many of them aren't going to be that common. However, as documented in
+the :class:`~django.http.HttpResponse` documentation, you can also pass the
+HTTP status code into the constructor for :class:`~django.http.HttpResponse`
+to create a return class for any status code you like. For example::
+ def my_view(request):
+ # ...
+ # Return a "created" (201) response code.
+ return HttpResponse(status=201)
Because 404 errors are by far the most common HTTP error, there's an easier way
to handle those errors.

0 comments on commit cbe11c1

Please sign in to comment.
Something went wrong with that request. Please try again.