diff options
| author | Santiago Basulto <santiago.basulto@gmail.com> | 2018-05-04 20:37:01 -0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-01-16 13:38:47 -0500 |
| commit | 4fc35a9c3efdc9154efce28cb23cb84f8834517e (patch) | |
| tree | a4f7b10244cb933d827cf72ef57dc11e68c1a6ca /docs/ref | |
| parent | aa5d0a5a90a690dc6f8fdbbffba143e32c86e40a (diff) | |
Fixed #20147 -- Added HttpRequest.headers.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/request-response.txt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 9e445ee4ff..84aa72da20 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -167,6 +167,38 @@ All attributes should be considered read-only, unless stated otherwise. underscores in WSGI environment variables. It matches the behavior of Web servers like Nginx and Apache 2.4+. + :attr:`HttpRequest.headers` is a simpler way to access all HTTP-prefixd + headers, plus ``CONTENT_LENGTH`` and ``CONTENT_TYPE``. + +.. attribute:: HttpRequest.headers + + .. versionadded:: 2.2 + + A case insensitive, dict-like object that provides access to all + HTTP-prefixed headers (plus ``Content-Length`` and ``Content-Type``) from + the request. + + The name of each header is stylized with title-casing (e.g. ``User-Agent``) + when it's displayed. You can access headers case-insensitively:: + + >>> request.headers + {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6', ...} + + >>> 'User-Agent' in request.headers + True + >>> 'user-agent' in request.headers + True + + >>> request.headers['User-Agent'] + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + >>> request.headers['user-agent'] + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + + >>> request.headers.get('User-Agent') + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + >>> request.headers.get('user-agent') + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + .. attribute:: HttpRequest.resolver_match An instance of :class:`~django.urls.ResolverMatch` representing the |
