summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-24 09:29:27 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-24 09:29:27 +0000
commit8613e6c53efe40f77e03541d56f68d0f583bcbdc (patch)
tree9ad01620d790fbb676e2db63d04e19315a498c13
parent122c1a9ac0e293a8efc3f1b0348540b02e5ad9f1 (diff)
[1.0.X] Fixed #9430 -- Fixed documentation references to the HttpResponse
classes for returning HTTP status codes other than 200. Backport of r9266 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9269 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--docs/ref/request-response.txt2
-rw-r--r--docs/topics/http/views.txt24
2 files changed, 21 insertions, 5 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index d8f4fe04a0..262b1276dc 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -525,6 +525,8 @@ Methods
.. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10
+.. _ref-httpresponse-subclasses:
+
HttpResponse subclasses
-----------------------
diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt
index 3b981c0442..7d8743fe06 100644
--- a/docs/topics/http/views.txt
+++ b/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
+example::
def my_view(request):
# ...
@@ -77,6 +79,18 @@ an error. For example::
else:
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.