Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Django - Request Objects

Back


Overview: Request and response objects


HttpRequest Objects

Attributes

Attributes Description
scheme the scheme of the request (http or https usually)
body The raw HTTP request body as a bytestring (data like binary images, XML)
path the full path to the requested page, except the scheme, domain, or query string.
method the HTTP method used in the request. "GET", "POST"
encoding the current encoding used to decode form submission data
content_type the MIME type of the request
content_params key/value parameters included in the CONTENT_TYPE header
GET A QueryDict object containing all given HTTP GET parameters.
POST A QueryDict object containing all given HTTP POST parameters
COOKIES A dictionary containing all cookies
FILES A dictionary-like object containing all uploaded files.
META A dictionary containing all available HTTP headers.
headers A case insensitive, dict-like object that provides access to all HTTP-prefixed headers

Methods

Method Description
get_host() Returns the host of the request
get_port() Returns the port of the request
get_full_path() Returns the path, plus an appended query string
build_absolute_uri() Returns the absolute URI form of location.
get_signed_cookie(key) Returns a cookie value for a signed cookie
is_secure() Returns True if the request is secure(made with HTTPS)
accepts(mime_type) Returns True if the request Accept header matches the mime_type argument
read(size=None) read an HttpRequest instance
readline() read an HttpRequest instance
readlines() read an HttpRequest instance
__iter__() read an HttpRequest instance

QueryDict Objects

Method Description
.get(key) Returns a list of the data with the requested key.
.getlist(key) Returns a mutable copy of the object.
.items() Return an iterable object with all key-value pairs
.lists() Like items, except it includes all values for each key
.values() Return an iterable object with all values
.copy() Returns a mutable copy of the object.
.dict() Returns a dict representation of QueryDict
.urlencode() Returns a string of the data in query string format.

TOP