diff --git a/docs/request_response.txt b/docs/request_response.txt new file mode 100644 index 0000000000..72119459be --- /dev/null +++ b/docs/request_response.txt @@ -0,0 +1,312 @@ +============================ +Request and response objects +============================ + +Quick overview +============== + +Django uses request and response objects to pass state through the system. + +When a page is requested, Django creates an ``HttpRequest`` object that +contains metadata about the request. Then Django loads the appropriate view, +passing the ``HttpRequest`` as the first argument to the view function. Each +view is responsible for returning an ``HttpResponse`` object. + +This document explains the APIs for ``HttpRequest`` and ``HttpResponse`` +objects. + +HttpRequest objects +=================== + +Attributes +---------- + +All attributes except ``session`` should be considered read-only. + +``path`` + A string representing the full path to the requested page, not including + the domain. + + Example: ``"/music/bands/the_beatles/"`` + +``GET`` + A dictionary-like object containing all given HTTP GET parameters. See the + ``MultiValueDict`` documentation below. + +``POST`` + A dictionary-like object containing all given HTTP POST parameters. See the + ``MultiValueDict`` documentation below. + +``REQUEST`` + For convenience, a dictionary-like object that searches ``POST`` first, + then ``GET``. Inspired by PHP's ``$_REQUEST``. + + For example, if ``GET = {"name": "john"}`` and ``POST = {"age": '34'}``, + ``REQUEST["name"]`` would be ``"john"``, and ``REQUEST["age"]`` would be + ``"34"``. + + It's strongly suggested that you use ``GET`` and ``POST`` instead of + ``REQUEST``, because the former are more explicit. + +``COOKIES`` + A standard Python dictionary containing all cookies. Keys and values are + strings. + +``FILES`` + A dictionary-like object containing all uploaded files. Each key in + ``FILES`` is the ``name`` from the ````. Each + value in ``FILES`` is a standard Python dictionary with the following three + keys: + + * ``filename`` -- The name of the uploaded file, as a Python string. + * ``content-type`` -- The content type of the uploaded file. + * ``content`` -- The raw content of the uploaded file. + + Note that ``FILES`` will only contain data if the request method was POST + and the ``