Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…sses for

returning HTTP status codes other than 200.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9266 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cbe11c1982b5519171a8caae6f99629899dc929b 1 parent 2f87035
Malcolm Tredinnick authored October 24, 2008
2  docs/ref/request-response.txt
@@ -525,6 +525,8 @@ Methods
525 525
 .. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10
526 526
 
527 527
 
  528
+.. _ref-httpresponse-subclasses:
  529
+
528 530
 HttpResponse subclasses
529 531
 -----------------------
530 532
 
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
64 64
 Returning errors
65 65
 ================
66 66
 
67  
-Returning HTTP error codes in Django is easy. We've already mentioned the
68  
-:class:`HttpResponseNotFound`, :class:`HttpResponseForbidden`,
69  
-:class:`HttpResponseServerError`, etc., subclasses; just return an instance of one
70  
-of those subclasses instead of a normal :class:`HttpResponse` in order to signify
71  
-an error. For example::
  67
+Returning HTTP error codes in Django is easy. There are subclasses of
  68
+:class:`~django.http.HttpResponse` for a number of common HTTP status codes
  69
+other than 200 (which means *"OK"*). You can find the full list of available
  70
+subclasses in the :ref:`request/response <ref-httpresponse-subclasses>`
  71
+documentation.  Just return an instance of one of those subclasses instead of
  72
+a normal :class:`~django.http.HttpResponse` in order to signify an error. For
  73
+example::
72 74
 
73 75
     def my_view(request):
74 76
         # ...
@@ -77,6 +79,18 @@ an error. For example::
77 79
         else:
78 80
             return HttpResponse('<h1>Page was found</h1>')
79 81
 
  82
+There isn't a specialized subclass for every possible HTTP response code,
  83
+since many of them aren't going to be that common. However, as documented in
  84
+the :class:`~django.http.HttpResponse` documentation, you can also pass the
  85
+HTTP status code into the constructor for :class:`~django.http.HttpResponse`
  86
+to create a return class for any status code you like. For example::
  87
+
  88
+    def my_view(request):
  89
+        # ...
  90
+
  91
+        # Return a "created" (201) response code.
  92
+        return HttpResponse(status=201)
  93
+
80 94
 Because 404 errors are by far the most common HTTP error, there's an easier way
81 95
 to handle those errors.
82 96
 

0 notes on commit cbe11c1

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