| 1 | = !HttpRequest = |
| 2 | |
| 3 | [[TOC]] |
| 4 | |
| 5 | Represents an incoming HTTP request, including all HTTP headers and user-submitted data. |
| 6 | |
| 7 | == Attributes == |
| 8 | |
| 9 | Unless otherwise noted, all attributes should be treated as read-only. Additional attributes may be added by [http://www.djangoproject.com/documentation/middleware/ middleware], as defined in a project's [http://www.djangoproject.com/documentation/settings/#middleware-classes settings]. Some attributes commonly added by middleware are listed here as well, with a link to the middleware documentation. |
| 10 | |
| 11 | || `path` || String containing the full path (not including domain) of the URL requested || |
| 12 | || `method` || Stringing containing the HTTP method used by the request (`'GET'` or `'POST'`) || |
| 13 | || `GET` || A QueryDict representing form values submitted using the HTTP `GET` method || |
| 14 | || `POST` || A QueryDict representing form values submitted using the HTTP `POST` method || |
| 15 | || `raw_post_data` || Unprocessed text of the complete POST data, only used in advanced cases, where POST data cannot be parsed into a `QueryDict` || |
| 16 | || `COOKIES` || A dictionary of cookies sent by the browser during the request || |
| 17 | || `META` || A dictionary of included HTTP headers; available headers will vary based on client and server || |
| 18 | || `user` || A `User` (or `AnonymousUser`) object from the [http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests authentication middleware] || |
| 19 | || `session` || A special read-write dictionary provided by the [http://www.djangoproject.com/documentation/sessions/ sessions middleware] || |
| 20 | |
| 21 | == Methods == |
| 22 | |
| 23 | || `has_key(key)` || Returns `True` if the given key was provided in the request (`GET` or `POST`). `False` otherwise || |
| 24 | || `get_full_path()` || Returns the full request string, including any query string that was provided || |
| 25 | || `is_secure()` || Returns `True` if the request was made using HTTPS, `False` otherwise || |
| 26 | |
| 27 | == Dictionary Syntax == |
| 28 | |
| 29 | !HttpRequest objects allow form data to be retrieved using standard Python dictionary syntax. It will check for `GET` data first, then `POST`. Like any dictionary, accessing a non-existant key will result in an `AttributeError`. This access is read-only. |
| 30 | |
| 31 | {{{ |
| 32 | #!python |
| 33 | username = request['username'] |
| 34 | }}} |