From 8c3c027e414c081bef469feb73f4d3e842f06b49 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 29 Apr 2006 02:11:02 +0000 Subject: [PATCH] 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 --- docs/request_response.txt | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/request_response.txt b/docs/request_response.txt index 696f186525..6fa4311f61 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -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 ``QueryDict`` documentation below. + Note: ``POST`` does *not* include file-upload information. See ``FILES``. + ``REQUEST`` For convenience, a dictionary-like object that searches ``POST`` first, 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. ``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 to an instance of ``django.contrib.auth.models.AnonymousUser``. You can tell them apart with ``is_anonymous()``, like so:: @@ -96,6 +98,12 @@ All attributes except ``session`` should be considered read-only. else: # 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`` A readable-and-writable, dictionary-like object that represents the current 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 of ``django.http.QueryDict``. ``QueryDict`` is a dictionary-like class customized to deal with multiple values for the same key. This is -necessary because some HTML form elements, notably ````, pass multiple values for the same key. ``QueryDict`` instances are immutable, unless you create a ``copy()`` of them. 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 ----- +Passing strings +~~~~~~~~~~~~~~~ + Typical usage is to pass the contents of the page, as a string, to the ``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. +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 ------- ``__init__(content='', mimetype=DEFAULT_MIME_TYPE)`` 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 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`` 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 - absolute URL with no domain (e.g. ``"/search/"``). Note that this returns + 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 an HTTP status code 302. ``HttpResponsePermanentRedirect``