PageRenderTime 49ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/ref/request-response.txt

https://code.google.com/p/mango-py/
Plain Text | 695 lines | 471 code | 224 blank | 0 comment | 0 complexity | 1cbd537d7bcd1d313ca85e60fd8e949a MD5 | raw file
  1============================
  2Request and response objects
  3============================
  4
  5.. module:: django.http
  6   :synopsis: Classes dealing with HTTP requests and responses.
  7
  8Quick overview
  9==============
 10
 11Django uses request and response objects to pass state through the system.
 12
 13When a page is requested, Django creates an :class:`HttpRequest` object that
 14contains metadata about the request. Then Django loads the appropriate view,
 15passing the :class:`HttpRequest` as the first argument to the view function.
 16Each view is responsible for returning an :class:`HttpResponse` object.
 17
 18This document explains the APIs for :class:`HttpRequest` and
 19:class:`HttpResponse` objects.
 20
 21HttpRequest objects
 22===================
 23
 24.. class:: HttpRequest
 25
 26Attributes
 27----------
 28
 29All attributes except ``session`` should be considered read-only.
 30
 31.. attribute:: HttpRequest.path
 32
 33    A string representing the full path to the requested page, not including
 34    the domain.
 35
 36    Example: ``"/music/bands/the_beatles/"``
 37
 38.. attribute:: HttpRequest.path_info
 39
 40    Under some Web server configurations, the portion of the URL after the host
 41    name is split up into a script prefix portion and a path info portion
 42    (this happens, for example, when using the ``django.root`` option
 43    with the :doc:`modpython handler from Apache </howto/deployment/modpython>`).
 44    The ``path_info`` attribute always contains the path info portion of the
 45    path, no matter what Web server is being used. Using this instead of
 46    attr:`~HttpRequest.path` can make your code much easier to move between test
 47    and deployment servers.
 48
 49    For example, if the ``django.root`` for your application is set to
 50    ``"/minfo"``, then ``path`` might be ``"/minfo/music/bands/the_beatles/"``
 51    and ``path_info`` would be ``"/music/bands/the_beatles/"``.
 52
 53.. attribute:: HttpRequest.method
 54
 55    A string representing the HTTP method used in the request. This is
 56    guaranteed to be uppercase. Example::
 57
 58        if request.method == 'GET':
 59            do_something()
 60        elif request.method == 'POST':
 61            do_something_else()
 62
 63.. attribute:: HttpRequest.encoding
 64
 65    A string representing the current encoding used to decode form submission
 66    data (or ``None``, which means the :setting:`DEFAULT_CHARSET` setting is
 67    used). You can write to this attribute to change the encoding used when
 68    accessing the form data. Any subsequent attribute accesses (such as reading
 69    from ``GET`` or ``POST``) will use the new ``encoding`` value.  Useful if
 70    you know the form data is not in the :setting:`DEFAULT_CHARSET` encoding.
 71
 72.. attribute:: HttpRequest.GET
 73
 74    A dictionary-like object containing all given HTTP GET parameters. See the
 75    :class:`QueryDict` documentation below.
 76
 77.. attribute:: HttpRequest.POST
 78
 79    A dictionary-like object containing all given HTTP POST parameters. See the
 80    :class:`QueryDict` documentation below.
 81
 82    It's possible that a request can come in via POST with an empty ``POST``
 83    dictionary -- if, say, a form is requested via the POST HTTP method but
 84    does not include form data. Therefore, you shouldn't use ``if request.POST``
 85    to check for use of the POST method; instead, use ``if request.method ==
 86    "POST"`` (see above).
 87
 88    Note: ``POST`` does *not* include file-upload information. See ``FILES``.
 89
 90.. attribute:: HttpRequest.REQUEST
 91
 92    For convenience, a dictionary-like object that searches ``POST`` first,
 93    then ``GET``. Inspired by PHP's ``$_REQUEST``.
 94
 95    For example, if ``GET = {"name": "john"}`` and ``POST = {"age": '34'}``,
 96    ``REQUEST["name"]`` would be ``"john"``, and ``REQUEST["age"]`` would be
 97    ``"34"``.
 98
 99    It's strongly suggested that you use ``GET`` and ``POST`` instead of
100    ``REQUEST``, because the former are more explicit.
101
102.. attribute:: HttpRequest.COOKIES
103
104    A standard Python dictionary containing all cookies. Keys and values are
105    strings.
106
107.. attribute:: HttpRequest.FILES
108
109    A dictionary-like object containing all uploaded files. Each key in
110    ``FILES`` is the ``name`` from the ``<input type="file" name="" />``. Each
111    value in ``FILES`` is an :class:`UploadedFile` as described below.
112
113    See :doc:`/topics/files` for more information.
114
115    Note that ``FILES`` will only contain data if the request method was POST
116    and the ``<form>`` that posted to the request had
117    ``enctype="multipart/form-data"``. Otherwise, ``FILES`` will be a blank
118    dictionary-like object.
119
120.. attribute:: HttpRequest.META
121
122    A standard Python dictionary containing all available HTTP headers.
123    Available headers depend on the client and server, but here are some
124    examples:
125
126        * ``CONTENT_LENGTH``
127        * ``CONTENT_TYPE``
128        * ``HTTP_ACCEPT_ENCODING``
129        * ``HTTP_ACCEPT_LANGUAGE``
130        * ``HTTP_HOST`` -- The HTTP Host header sent by the client.
131        * ``HTTP_REFERER`` -- The referring page, if any.
132        * ``HTTP_USER_AGENT`` -- The client's user-agent string.
133        * ``QUERY_STRING`` -- The query string, as a single (unparsed) string.
134        * ``REMOTE_ADDR`` -- The IP address of the client.
135        * ``REMOTE_HOST`` -- The hostname of the client.
136        * ``REMOTE_USER`` -- The user authenticated by the Web server, if any.
137        * ``REQUEST_METHOD`` -- A string such as ``"GET"`` or ``"POST"``.
138        * ``SERVER_NAME`` -- The hostname of the server.
139        * ``SERVER_PORT`` -- The port of the server.
140
141    With the exception of ``CONTENT_LENGTH`` and ``CONTENT_TYPE``, as given
142    above, any HTTP headers in the request are converted to ``META`` keys by
143    converting all characters to uppercase, replacing any hyphens with
144    underscores and adding an ``HTTP_`` prefix to the name. So, for example, a
145    header called ``X-Bender`` would be mapped to the ``META`` key
146    ``HTTP_X_BENDER``.
147
148.. attribute:: HttpRequest.user
149
150    A ``django.contrib.auth.models.User`` object representing the currently
151    logged-in user. If the user isn't currently logged in, ``user`` will be set
152    to an instance of ``django.contrib.auth.models.AnonymousUser``. You
153    can tell them apart with ``is_authenticated()``, like so::
154
155        if request.user.is_authenticated():
156            # Do something for logged-in users.
157        else:
158            # Do something for anonymous users.
159
160    ``user`` is only available if your Django installation has the
161    ``AuthenticationMiddleware`` activated. For more, see
162    :doc:`/topics/auth`.
163
164.. attribute:: HttpRequest.session
165
166    A readable-and-writable, dictionary-like object that represents the current
167    session. This is only available if your Django installation has session
168    support activated. See the :doc:`session documentation
169    </topics/http/sessions>` for full details.
170
171.. attribute:: HttpRequest.raw_post_data
172
173    The raw HTTP POST data as a byte string. This is useful for processing
174    data in different formats than of conventional HTML forms: binary images,
175    XML payload etc. For processing form data use ``HttpRequest.POST``.
176
177    .. versionadded:: 1.3
178
179    You can also read from an HttpRequest using file-like interface. See
180    :meth:`HttpRequest.read()`.
181
182.. attribute:: HttpRequest.urlconf
183
184    Not defined by Django itself, but will be read if other code (e.g., a custom
185    middleware class) sets it. When present, this will be used as the root
186    URLconf for the current request, overriding the :setting:`ROOT_URLCONF`
187    setting. See :ref:`how-django-processes-a-request` for details.
188
189Methods
190-------
191
192.. method:: HttpRequest.get_host()
193
194    Returns the originating host of the request using information from
195    the ``HTTP_X_FORWARDED_HOST`` (if enabled in the settings) and ``HTTP_HOST``
196    headers (in that order). If they don't provide a value, the method
197    uses a combination of ``SERVER_NAME`` and ``SERVER_PORT`` as
198    detailed in :pep:`3333`.
199
200    .. _PEP 333: http://www.python.org/dev/peps/pep-0333/
201
202    Example: ``"127.0.0.1:8000"``
203
204    .. note:: The :meth:`~HttpRequest.get_host()` method fails when the host is
205        behind multiple proxies. One solution is to use middleware to rewrite
206        the proxy headers, as in the following example::
207
208            class MultipleProxyMiddleware(object):
209                FORWARDED_FOR_FIELDS = [
210                    'HTTP_X_FORWARDED_FOR',
211                    'HTTP_X_FORWARDED_HOST',
212                    'HTTP_X_FORWARDED_SERVER',
213                ]
214
215                def process_request(self, request):
216                    """
217                    Rewrites the proxy headers so that only the most
218                    recent proxy is used.
219                    """
220                    for field in self.FORWARDED_FOR_FIELDS:
221                        if field in request.META:
222                            if ',' in request.META[field]:
223                                parts = request.META[field].split(',')
224                                request.META[field] = parts[-1].strip()
225
226
227.. method:: HttpRequest.get_full_path()
228
229   Returns the ``path``, plus an appended query string, if applicable.
230
231   Example: ``"/music/bands/the_beatles/?print=true"``
232
233.. method:: HttpRequest.build_absolute_uri(location)
234
235   Returns the absolute URI form of ``location``. If no location is provided,
236   the location will be set to ``request.get_full_path()``.
237
238   If the location is already an absolute URI, it will not be altered.
239   Otherwise the absolute URI is built using the server variables available in
240   this request.
241
242   Example: ``"http://example.com/music/bands/the_beatles/?print=true"``
243
244.. method:: HttpRequest.is_secure()
245
246   Returns ``True`` if the request is secure; that is, if it was made with
247   HTTPS.
248
249.. method:: HttpRequest.is_ajax()
250
251   Returns ``True`` if the request was made via an ``XMLHttpRequest``, by
252   checking the ``HTTP_X_REQUESTED_WITH`` header for the string
253   ``'XMLHttpRequest'``. Most modern JavaScript libraries send this header.
254   If you write your own XMLHttpRequest call (on the browser side), you'll
255   have to set this header manually if you want ``is_ajax()`` to work.
256
257.. method:: HttpRequest.read(size=None)
258.. method:: HttpRequest.readline()
259.. method:: HttpRequest.readlines()
260.. method:: HttpRequest.xreadlines()
261.. method:: HttpRequest.__iter__()
262
263    .. versionadded:: 1.3
264
265    Methods implementing a file-like interface for reading from an
266    HttpRequest instance. This makes it possible to consume an incoming
267    request in a streaming fashion. A common use-case would be to process a
268    big XML payload with iterative parser without constructing a whole
269    XML tree in memory.
270
271    Given this standard interface, an HttpRequest instance can be
272    passed directly to an XML parser such as ElementTree::
273
274        import xml.etree.ElementTree as ET
275        for element in ET.iterparse(request):
276            process(element)
277
278
279UploadedFile objects
280====================
281
282.. class:: UploadedFile
283
284
285Attributes
286----------
287
288.. attribute::  UploadedFile.name
289
290    The name of the uploaded file.
291
292.. attribute:: UploadedFile.size
293
294    The size, in bytes, of the uploaded file.
295
296Methods
297----------
298
299.. method:: UploadedFile.chunks(chunk_size=None)
300
301    Returns a generator that yields sequential chunks of data.
302
303.. method:: UploadedFile.read(num_bytes=None)
304
305    Read a number of bytes from the file.
306
307
308
309QueryDict objects
310=================
311
312.. class:: QueryDict
313
314In an :class:`HttpRequest` object, the ``GET`` and ``POST`` attributes are instances
315of ``django.http.QueryDict``. :class:`QueryDict` is a dictionary-like
316class customized to deal with multiple values for the same key. This is
317necessary because some HTML form elements, notably
318``<select multiple="multiple">``, pass multiple values for the same key.
319
320``QueryDict`` instances are immutable, unless you create a ``copy()`` of them.
321That means you can't change attributes of ``request.POST`` and ``request.GET``
322directly.
323
324Methods
325-------
326
327:class:`QueryDict` implements all the standard dictionary methods, because it's
328a subclass of dictionary. Exceptions are outlined here:
329
330.. method:: QueryDict.__getitem__(key)
331
332    Returns the value for the given key. If the key has more than one value,
333    ``__getitem__()`` returns the last value. Raises
334    ``django.utils.datastructures.MultiValueDictKeyError`` if the key does not
335    exist. (This is a subclass of Python's standard ``KeyError``, so you can
336    stick to catching ``KeyError``.)
337
338.. method:: QueryDict.__setitem__(key, value)
339
340    Sets the given key to ``[value]`` (a Python list whose single element is
341    ``value``). Note that this, as other dictionary functions that have side
342    effects, can only be called on a mutable ``QueryDict`` (one that was created
343    via ``copy()``).
344
345.. method:: QueryDict.__contains__(key)
346
347    Returns ``True`` if the given key is set. This lets you do, e.g., ``if "foo"
348    in request.GET``.
349
350.. method:: QueryDict.get(key, default)
351
352    Uses the same logic as ``__getitem__()`` above, with a hook for returning a
353    default value if the key doesn't exist.
354
355.. method:: QueryDict.setdefault(key, default)
356
357    Just like the standard dictionary ``setdefault()`` method, except it uses
358    ``__setitem__()`` internally.
359
360.. method:: QueryDict.update(other_dict)
361
362    Takes either a ``QueryDict`` or standard dictionary. Just like the standard
363    dictionary ``update()`` method, except it *appends* to the current
364    dictionary items rather than replacing them. For example::
365
366          >>> q = QueryDict('a=1')
367          >>> q = q.copy() # to make it mutable
368          >>> q.update({'a': '2'})
369          >>> q.getlist('a')
370          [u'1', u'2']
371          >>> q['a'] # returns the last
372          [u'2']
373
374.. method:: QueryDict.items()
375
376    Just like the standard dictionary ``items()`` method, except this uses the
377    same last-value logic as ``__getitem__()``. For example::
378
379           >>> q = QueryDict('a=1&a=2&a=3')
380           >>> q.items()
381           [(u'a', u'3')]
382
383.. method:: QueryDict.iteritems()
384
385    Just like the standard dictionary ``iteritems()`` method. Like
386    :meth:`QueryDict.items()` this uses the same last-value logic as
387    :meth:`QueryDict.__getitem__()`.
388
389.. method:: QueryDict.iterlists()
390
391    Like :meth:`QueryDict.iteritems()` except it includes all values, as a list,
392    for each member of the dictionary.
393
394.. method:: QueryDict.values()
395
396    Just like the standard dictionary ``values()`` method, except this uses the
397    same last-value logic as ``__getitem__()``. For example::
398
399           >>> q = QueryDict('a=1&a=2&a=3')
400           >>> q.values()
401           [u'3']
402
403.. method:: QueryDict.itervalues()
404
405    Just like :meth:`QueryDict.values()`, except an iterator.
406
407In addition, ``QueryDict`` has the following methods:
408
409.. method:: QueryDict.copy()
410
411    Returns a copy of the object, using ``copy.deepcopy()`` from the Python
412    standard library. The copy will be mutable -- that is, you can change its
413    values.
414
415.. method:: QueryDict.getlist(key)
416
417    Returns the data with the requested key, as a Python list. Returns an
418    empty list if the key doesn't exist. It's guaranteed to return a list of
419    some sort.
420
421.. method:: QueryDict.setlist(key, list_)
422
423    Sets the given key to ``list_`` (unlike ``__setitem__()``).
424
425.. method:: QueryDict.appendlist(key, item)
426
427    Appends an item to the internal list associated with key.
428
429.. method:: QueryDict.setlistdefault(key, default_list)
430
431    Just like ``setdefault``, except it takes a list of values instead of a
432    single value.
433
434.. method:: QueryDict.lists()
435
436    Like :meth:`items()`, except it includes all values, as a list, for each
437    member of the dictionary. For example::
438
439        >>> q = QueryDict('a=1&a=2&a=3')
440        >>> q.lists()
441        [(u'a', [u'1', u'2', u'3'])]
442
443.. method:: QueryDict.urlencode([safe])
444
445    Returns a string of the data in query-string format. Example::
446
447        >>> q = QueryDict('a=2&b=3&b=5')
448        >>> q.urlencode()
449        'a=2&b=3&b=5'
450
451    .. versionchanged:: 1.3
452       The ``safe`` parameter was added.
453
454    Optionally, urlencode can be passed characters which
455    do not require encoding. For example::
456
457        >>> q = QueryDict('', mutable=True)
458        >>> q['next'] = '/a&b/'
459        >>> q.urlencode(safe='/')
460        'next=/a%26b/'
461
462HttpResponse objects
463====================
464
465.. class:: HttpResponse
466
467In contrast to :class:`HttpRequest` objects, which are created automatically by
468Django, :class:`HttpResponse` objects are your responsibility. Each view you
469write is responsible for instantiating, populating and returning an
470:class:`HttpResponse`.
471
472The :class:`HttpResponse` class lives in the :mod:`django.http` module.
473
474Usage
475-----
476
477Passing strings
478~~~~~~~~~~~~~~~
479
480Typical usage is to pass the contents of the page, as a string, to the
481:class:`HttpResponse` constructor::
482
483    >>> response = HttpResponse("Here's the text of the Web page.")
484    >>> response = HttpResponse("Text only, please.", mimetype="text/plain")
485
486But if you want to add content incrementally, you can use ``response`` as a
487file-like object::
488
489    >>> response = HttpResponse()
490    >>> response.write("<p>Here's the text of the Web page.</p>")
491    >>> response.write("<p>Here's another paragraph.</p>")
492
493Passing iterators
494~~~~~~~~~~~~~~~~~
495
496Finally, you can pass ``HttpResponse`` an iterator rather than passing it
497hard-coded strings. If you use this technique, follow these guidelines:
498
499    * The iterator should return strings.
500    * If an :class:`HttpResponse` has been initialized with an iterator as its
501      content, you can't use the class:`HttpResponse` instance as a file-like
502      object. Doing so will raise ``Exception``.
503
504Setting headers
505~~~~~~~~~~~~~~~
506
507To set or remove a header in your response, treat it like a dictionary::
508
509    >>> response = HttpResponse()
510    >>> response['Cache-Control'] = 'no-cache'
511    >>> del response['Cache-Control']
512
513Note that unlike a dictionary, ``del`` doesn't raise ``KeyError`` if the header
514doesn't exist.
515
516HTTP headers cannot contain newlines. An attempt to set a header containing a
517newline character (CR or LF) will raise ``BadHeaderError``
518
519Telling the browser to treat the response as a file attachment
520~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
521
522To tell the browser to treat the response as a file attachment, use the
523``mimetype`` argument and set the ``Content-Disposition`` header. For example,
524this is how you might return a Microsoft Excel spreadsheet::
525
526    >>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel')
527    >>> response['Content-Disposition'] = 'attachment; filename=foo.xls'
528
529There's nothing Django-specific about the ``Content-Disposition`` header, but
530it's easy to forget the syntax, so we've included it here.
531
532Attributes
533----------
534
535.. attribute:: HttpResponse.content
536
537    A normal Python string representing the content, encoded from a Unicode
538    object if necessary.
539
540.. attribute:: HttpResponse.status_code
541
542    The `HTTP Status code`_ for the response.
543
544Methods
545-------
546
547.. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE)
548
549    Instantiates an ``HttpResponse`` object with the given page content (a
550    string) and MIME type. The :setting:`DEFAULT_CONTENT_TYPE` is
551    ``'text/html'``.
552
553    ``content`` can be an iterator or a string. If it's an iterator, it should
554    return strings, and those strings will be joined together to form the
555    content of the response.
556
557    ``status`` is the `HTTP Status code`_ for the response.
558
559    ``content_type`` is an alias for ``mimetype``. Historically, this parameter
560    was only called ``mimetype``, but since this is actually the value included
561    in the HTTP ``Content-Type`` header, it can also include the character set
562    encoding, which makes it more than just a MIME type specification.
563    If ``mimetype`` is specified (not ``None``), that value is used.
564    Otherwise, ``content_type`` is used. If neither is given, the
565    :setting:`DEFAULT_CONTENT_TYPE` setting is used.
566
567.. method:: HttpResponse.__setitem__(header, value)
568
569    Sets the given header name to the given value. Both ``header`` and
570    ``value`` should be strings.
571
572.. method:: HttpResponse.__delitem__(header)
573
574    Deletes the header with the given name. Fails silently if the header
575    doesn't exist. Case-insensitive.
576
577.. method:: HttpResponse.__getitem__(header)
578
579    Returns the value for the given header name. Case-insensitive.
580
581.. method:: HttpResponse.has_header(header)
582
583    Returns ``True`` or ``False`` based on a case-insensitive check for a
584    header with the given name.
585
586.. method:: HttpResponse.set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=False)
587
588    .. versionchanged:: 1.3
589
590    The possibility of specifying a ``datetime.datetime`` object in
591    ``expires``, and the auto-calculation of ``max_age`` in such case
592    was added. The ``httponly`` argument was also added.
593
594    Sets a cookie. The parameters are the same as in the `cookie Morsel`_
595    object in the Python standard library.
596
597        * ``max_age`` should be a number of seconds, or ``None`` (default) if
598          the cookie should last only as long as the client's browser session.
599          If ``expires`` is not specified, it will be calculated.
600        * ``expires`` should either be a string in the format
601          ``"Wdy, DD-Mon-YY HH:MM:SS GMT"`` or a ``datetime.datetime`` object
602          in UTC. If ``expires`` is a ``datetime`` object, the ``max_age``
603          will be calculated.
604        * Use ``domain`` if you want to set a cross-domain cookie. For example,
605          ``domain=".lawrence.com"`` will set a cookie that is readable by
606          the domains www.lawrence.com, blogs.lawrence.com and
607          calendars.lawrence.com. Otherwise, a cookie will only be readable by
608          the domain that set it.
609        * Use ``httponly=True`` if you want to prevent client-side
610          JavaScript from having access to the cookie.
611
612          HTTPOnly_ is a flag included in a Set-Cookie HTTP response
613          header. It is not part of the RFC2109 standard for cookies,
614          and it isn't honored consistently by all browsers. However,
615          when it is honored, it can be a useful way to mitigate the
616          risk of client side script accessing the protected cookie
617          data.
618
619    .. _`cookie Morsel`: http://docs.python.org/library/cookie.html#Cookie.Morsel
620    .. _HTTPOnly: http://www.owasp.org/index.php/HTTPOnly
621
622.. method:: HttpResponse.delete_cookie(key, path='/', domain=None)
623
624    Deletes the cookie with the given key. Fails silently if the key doesn't
625    exist.
626
627    Due to the way cookies work, ``path`` and ``domain`` should be the same
628    values you used in ``set_cookie()`` -- otherwise the cookie may not be
629    deleted.
630
631.. method:: HttpResponse.write(content)
632
633    This method makes an :class:`HttpResponse` instance a file-like object.
634
635.. method:: HttpResponse.flush()
636
637    This method makes an :class:`HttpResponse` instance a file-like object.
638
639.. method:: HttpResponse.tell()
640
641    This method makes an :class:`HttpResponse` instance a file-like object.
642
643.. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10
644
645
646.. _ref-httpresponse-subclasses:
647
648HttpResponse subclasses
649-----------------------
650
651Django includes a number of ``HttpResponse`` subclasses that handle different
652types of HTTP responses. Like ``HttpResponse``, these subclasses live in
653:mod:`django.http`.
654
655.. class:: HttpResponseRedirect
656
657    The constructor takes a single argument -- the path to redirect to. This
658    can be a fully qualified URL (e.g. ``'http://www.yahoo.com/search/'``) or
659    an absolute path with no domain (e.g. ``'/search/'``). Note that this
660    returns an HTTP status code 302.
661
662.. class:: HttpResponsePermanentRedirect
663
664    Like :class:`HttpResponseRedirect`, but it returns a permanent redirect
665    (HTTP status code 301) instead of a "found" redirect (status code 302).
666
667.. class:: HttpResponseNotModified
668
669    The constructor doesn't take any arguments. Use this to designate that a
670    page hasn't been modified since the user's last request (status code 304).
671
672.. class:: HttpResponseBadRequest
673
674    Acts just like :class:`HttpResponse` but uses a 400 status code.
675
676.. class:: HttpResponseNotFound
677
678    Acts just like :class:`HttpResponse` but uses a 404 status code.
679
680.. class:: HttpResponseForbidden
681
682    Acts just like :class:`HttpResponse` but uses a 403 status code.
683
684.. class:: HttpResponseNotAllowed
685
686    Like :class:`HttpResponse`, but uses a 405 status code. Takes a single,
687    required argument: a list of permitted methods (e.g. ``['GET', 'POST']``).
688
689.. class:: HttpResponseGone
690
691    Acts just like :class:`HttpResponse` but uses a 410 status code.
692
693.. class:: HttpResponseServerError
694
695    Acts just like :class:`HttpResponse` but uses a 500 status code.