1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

magic-removal: Proofread docs/request_response.txt

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-04-29 02:11:02 +00:00
parent a5bae83575
commit 8c3c027e41

View File

@ -37,6 +37,8 @@ All attributes except ``session`` should be considered read-only.
A dictionary-like object containing all given HTTP POST parameters. See the A dictionary-like object containing all given HTTP POST parameters. See the
``QueryDict`` documentation below. ``QueryDict`` documentation below.
Note: ``POST`` does *not* include file-upload information. See ``FILES``.
``REQUEST`` ``REQUEST``
For convenience, a dictionary-like object that searches ``POST`` first, For convenience, a dictionary-like object that searches ``POST`` first,
then ``GET``. Inspired by PHP's ``$_REQUEST``. then ``GET``. Inspired by PHP's ``$_REQUEST``.
@ -86,7 +88,7 @@ All attributes except ``session`` should be considered read-only.
* ``SERVER_PORT`` -- The port of the server. * ``SERVER_PORT`` -- The port of the server.
``user`` ``user``
A ``django.models.auth.users.User`` object representing the currently A ``django.contrib.auth.models.User`` object representing the currently
logged-in user. If the user isn't currently logged in, ``user`` will be set logged-in user. If the user isn't currently logged in, ``user`` will be set
to an instance of ``django.contrib.auth.models.AnonymousUser``. You to an instance of ``django.contrib.auth.models.AnonymousUser``. You
can tell them apart with ``is_anonymous()``, like so:: can tell them apart with ``is_anonymous()``, like so::
@ -96,6 +98,12 @@ All attributes except ``session`` should be considered read-only.
else: else:
# Do something for logged-in users. # Do something for logged-in users.
``user`` is only available if your Django installation has the
``AuthenticationMiddleware`` activated. For more, see
`Authentication in Web requests`_.
.. Authentication in Web requests: http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests
``session`` ``session``
A readable-and-writable, dictionary-like object that represents the current A readable-and-writable, dictionary-like object that represents the current
session. This is only available if your Django installation has session session. This is only available if your Django installation has session
@ -133,8 +141,8 @@ QueryDict objects
In an ``HttpRequest`` object, the ``GET`` and ``POST`` attributes are instances In an ``HttpRequest`` object, the ``GET`` and ``POST`` attributes are instances
of ``django.http.QueryDict``. ``QueryDict`` is a dictionary-like of ``django.http.QueryDict``. ``QueryDict`` is a dictionary-like
class customized to deal with multiple values for the same key. This is class customized to deal with multiple values for the same key. This is
necessary because some HTML form elements, notably ``<select multiple>``, pass necessary because some HTML form elements, notably
multiple values for the same key. ``<select multiple="multiple">``, pass multiple values for the same key.
``QueryDict`` instances are immutable, unless you create a ``copy()`` of them. ``QueryDict`` instances are immutable, unless you create a ``copy()`` of them.
That means you can't change attributes of ``request.POST`` and ``request.GET`` That means you can't change attributes of ``request.POST`` and ``request.GET``
@ -274,6 +282,9 @@ The ``HttpResponse`` class lives at ``django.http.HttpResponse``.
Usage Usage
----- -----
Passing strings
~~~~~~~~~~~~~~~
Typical usage is to pass the contents of the page, as a string, to the Typical usage is to pass the contents of the page, as a string, to the
``HttpResponse`` constructor:: ``HttpResponse`` constructor::
@ -297,12 +308,23 @@ You can add and delete headers using dictionary syntax::
Note that ``del`` doesn't raise ``KeyError`` if the header doesn't exist. Note that ``del`` doesn't raise ``KeyError`` if the header doesn't exist.
Passing iterators
~~~~~~~~~~~~~~~~~
Finally, you can pass ``HttpResponse`` an iterator rather than passing it
hard-coded strings. If you use this technique, follow these guidelines:
* The iterator should return strings.
* If an ``HttpResponse`` has been initialized with an iterator as its
content, you can't use the ``HttpResponse`` instance as a file-like
object. Doing so will raise ``Exception``.
Methods Methods
------- -------
``__init__(content='', mimetype=DEFAULT_MIME_TYPE)`` ``__init__(content='', mimetype=DEFAULT_MIME_TYPE)``
Instantiates an ``HttpResponse`` object with the given page content (a Instantiates an ``HttpResponse`` object with the given page content (a
string) and MIME type. The ``DEFAULT_MIME_TYPE`` is ``"text/html"``. string) and MIME type. The ``DEFAULT_MIME_TYPE`` is ``'text/html'``.
``content`` can be an iterator or a string. If it's an iterator, it should ``content`` can be an iterator or a string. If it's an iterator, it should
return strings, and those strings will be joined together to form the return strings, and those strings will be joined together to form the
@ -360,8 +382,8 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in
``HttpResponseRedirect`` ``HttpResponseRedirect``
The constructor takes a single argument -- the path to redirect to. This The constructor takes a single argument -- the path to redirect to. This
can be a fully qualified URL (e.g. ``"http://www.yahoo.com/search/"``) or an can be a fully qualified URL (e.g. ``'http://www.yahoo.com/search/'``) or an
absolute URL with no domain (e.g. ``"/search/"``). Note that this returns absolute URL with no domain (e.g. ``'/search/'``). Note that this returns
an HTTP status code 302. an HTTP status code 302.
``HttpResponsePermanentRedirect`` ``HttpResponsePermanentRedirect``