doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
class LinearRing(*args, **kwargs) LinearRing objects are constructed in the exact same way as LineString objects, however the coordinates must be closed, in other words, the first coordinates must be the same as the last coordinates. For example: >>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0)) Notice that (0, 0) is the first and last coordinate – if they were not equal, an error would be raised. is_counterclockwise Returns whether this LinearRing is counterclockwise.
django.ref.contrib.gis.geos#django.contrib.gis.geos.LinearRing
is_counterclockwise Returns whether this LinearRing is counterclockwise.
django.ref.contrib.gis.geos#django.contrib.gis.geos.LinearRing.is_counterclockwise
class LineString(*args, **kwargs) LineString objects are instantiated using arguments that are either a sequence of coordinates or Point objects. For example, the following are equivalent: >>> ls = LineString((0, 0), (1, 1)) >>> ls = LineString(Point(0, 0), Point(1, 1)) In addition, LineString objects may also be created by passing in a single sequence of coordinate or Point objects: >>> ls = LineString( ((0, 0), (1, 1)) ) >>> ls = LineString( [Point(0, 0), Point(1, 1)] ) Empty LineString objects may be instantiated by passing no arguments or an empty sequence. The following are equivalent: >>> ls = LineString() >>> ls = LineString([]) closed Returns whether or not this LineString is closed.
django.ref.contrib.gis.geos#django.contrib.gis.geos.LineString
closed Returns whether or not this LineString is closed.
django.ref.contrib.gis.geos#django.contrib.gis.geos.LineString.closed
class MultiLineString(*args, **kwargs) MultiLineString objects may be instantiated by passing in LineString objects as arguments, or a single sequence of LineString objects: >>> ls1 = LineString((0, 0), (1, 1)) >>> ls2 = LineString((2, 2), (3, 3)) >>> mls = MultiLineString(ls1, ls2) >>> mls = MultiLineString([ls1, ls2]) merged Returns a LineString representing the line merge of all the components in this MultiLineString. closed Returns True if and only if all elements are closed.
django.ref.contrib.gis.geos#django.contrib.gis.geos.MultiLineString
closed Returns True if and only if all elements are closed.
django.ref.contrib.gis.geos#django.contrib.gis.geos.MultiLineString.closed
merged Returns a LineString representing the line merge of all the components in this MultiLineString.
django.ref.contrib.gis.geos#django.contrib.gis.geos.MultiLineString.merged
class MultiPoint(*args, **kwargs) MultiPoint objects may be instantiated by passing in Point objects as arguments, or a single sequence of Point objects: >>> mp = MultiPoint(Point(0, 0), Point(1, 1)) >>> mp = MultiPoint( (Point(0, 0), Point(1, 1)) )
django.ref.contrib.gis.geos#django.contrib.gis.geos.MultiPoint
class MultiPolygon(*args, **kwargs) MultiPolygon objects may be instantiated by passing Polygon objects as arguments, or a single sequence of Polygon objects: >>> p1 = Polygon( ((0, 0), (0, 1), (1, 1), (0, 0)) ) >>> p2 = Polygon( ((1, 1), (1, 2), (2, 2), (1, 1)) ) >>> mp = MultiPolygon(p1, p2) >>> mp = MultiPolygon([p1, p2])
django.ref.contrib.gis.geos#django.contrib.gis.geos.MultiPolygon
class Point(x=None, y=None, z=None, srid=None) Point objects are instantiated using arguments that represent the component coordinates of the point or with a single sequence coordinates. For example, the following are equivalent: >>> pnt = Point(5, 23) >>> pnt = Point([5, 23]) Empty Point objects may be instantiated by passing no arguments or an empty sequence. The following are equivalent: >>> pnt = Point() >>> pnt = Point([])
django.ref.contrib.gis.geos#django.contrib.gis.geos.Point
class Polygon(*args, **kwargs) Polygon objects may be instantiated by passing in parameters that represent the rings of the polygon. The parameters must either be LinearRing instances, or a sequence that may be used to construct a LinearRing: >>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)) >>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4)) >>> poly = Polygon(ext_coords, int_coords) >>> poly = Polygon(LinearRing(ext_coords), LinearRing(int_coords)) classmethod from_bbox(bbox) Returns a polygon object from the given bounding-box, a 4-tuple comprising (xmin, ymin, xmax, ymax). num_interior_rings Returns the number of interior rings in this geometry.
django.ref.contrib.gis.geos#django.contrib.gis.geos.Polygon
num_interior_rings Returns the number of interior rings in this geometry.
django.ref.contrib.gis.geos#django.contrib.gis.geos.Polygon.num_interior_rings
class PreparedGeometry All methods on PreparedGeometry take an other argument, which must be a GEOSGeometry instance. contains(other) contains_properly(other) covers(other) crosses(other) disjoint(other) intersects(other) overlaps(other) touches(other) within(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry
contains(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.contains
contains_properly(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.contains_properly
covers(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.covers
crosses(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.crosses
disjoint(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.disjoint
intersects(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.intersects
overlaps(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.overlaps
touches(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.touches
within(other)
django.ref.contrib.gis.geos#django.contrib.gis.geos.PreparedGeometry.within
class WKBReader Example: >>> from django.contrib.gis.geos import WKBReader >>> wkb_r = WKBReader() >>> wkb_r.read('0101000000000000000000F03F000000000000F03F') <Point object at 0x103a88910>
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBReader
class WKBWriter(dim=2) WKBWriter provides the most control over its output. By default it returns OGC-compliant WKB when its write method is called. However, it has properties that allow for the creation of EWKB, a superset of the WKB standard that includes additional information. See the WKBWriter.outdim documentation for more details about the dim argument. write(geom) Returns the WKB of the given geometry as a Python buffer object. Example: >>> from django.contrib.gis.geos import Point, WKBWriter >>> pnt = Point(1, 1) >>> wkb_w = WKBWriter() >>> wkb_w.write(pnt) <read-only buffer for 0x103a898f0, size -1, offset 0 at 0x103a89930> write_hex(geom) Returns WKB of the geometry in hexadecimal. Example: >>> from django.contrib.gis.geos import Point, WKBWriter >>> pnt = Point(1, 1) >>> wkb_w = WKBWriter() >>> wkb_w.write_hex(pnt) '0101000000000000000000F03F000000000000F03F' byteorder This property may be set to change the byte-order of the geometry representation. Byteorder Value Description 0 Big Endian (e.g., compatible with RISC systems) 1 Little Endian (e.g., compatible with x86 systems) Example: >>> from django.contrib.gis.geos import Point, WKBWriter >>> wkb_w = WKBWriter() >>> pnt = Point(1, 1) >>> wkb_w.write_hex(pnt) '0101000000000000000000F03F000000000000F03F' >>> wkb_w.byteorder = 0 '00000000013FF00000000000003FF0000000000000' outdim This property may be set to change the output dimension of the geometry representation. In other words, if you have a 3D geometry then set to 3 so that the Z value is included in the WKB. Outdim Value Description 2 The default, output 2D WKB. 3 Output 3D WKB. Example: >>> from django.contrib.gis.geos import Point, WKBWriter >>> wkb_w = WKBWriter() >>> wkb_w.outdim 2 >>> pnt = Point(1, 1, 1) >>> wkb_w.write_hex(pnt) # By default, no Z value included: '0101000000000000000000F03F000000000000F03F' >>> wkb_w.outdim = 3 # Tell writer to include Z values >>> wkb_w.write_hex(pnt) '0101000080000000000000F03F000000000000F03F000000000000F03F' srid Set this property with a boolean to indicate whether the SRID of the geometry should be included with the WKB representation. Example: >>> from django.contrib.gis.geos import Point, WKBWriter >>> wkb_w = WKBWriter() >>> pnt = Point(1, 1, srid=4326) >>> wkb_w.write_hex(pnt) # By default, no SRID included: '0101000000000000000000F03F000000000000F03F' >>> wkb_w.srid = True # Tell writer to include SRID >>> wkb_w.write_hex(pnt) '0101000020E6100000000000000000F03F000000000000F03F'
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter
byteorder
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter.byteorder
outdim
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter.outdim
srid
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter.srid
write(geom)
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter.write
write_hex(geom)
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKBWriter.write_hex
class WKTReader Example: >>> from django.contrib.gis.geos import WKTReader >>> wkt_r = WKTReader() >>> wkt_r.read('POINT(1 1)') <Point object at 0x103a88b50>
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTReader
class WKTWriter(dim=2, trim=False, precision=None) This class allows outputting the WKT representation of a geometry. See the WKBWriter.outdim, trim, and precision attributes for details about the constructor arguments. write(geom) Returns the WKT of the given geometry. Example: >>> from django.contrib.gis.geos import Point, WKTWriter >>> pnt = Point(1, 1) >>> wkt_w = WKTWriter() >>> wkt_w.write(pnt) 'POINT (1.0000000000000000 1.0000000000000000)' outdim See WKBWriter.outdim. trim This property is used to enable or disable trimming of unnecessary decimals. >>> from django.contrib.gis.geos import Point, WKTWriter >>> pnt = Point(1, 1) >>> wkt_w = WKTWriter() >>> wkt_w.trim False >>> wkt_w.write(pnt) 'POINT (1.0000000000000000 1.0000000000000000)' >>> wkt_w.trim = True >>> wkt_w.write(pnt) 'POINT (1 1)' precision This property controls the rounding precision of coordinates; if set to None rounding is disabled. >>> from django.contrib.gis.geos import Point, WKTWriter >>> pnt = Point(1.44, 1.66) >>> wkt_w = WKTWriter() >>> print(wkt_w.precision) None >>> wkt_w.write(pnt) 'POINT (1.4399999999999999 1.6599999999999999)' >>> wkt_w.precision = 0 >>> wkt_w.write(pnt) 'POINT (1 2)' >>> wkt_w.precision = 1 >>> wkt_w.write(pnt) 'POINT (1.4 1.7)'
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTWriter
outdim See WKBWriter.outdim.
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTWriter.outdim
precision
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTWriter.precision
trim
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTWriter.trim
write(geom)
django.ref.contrib.gis.geos#django.contrib.gis.geos.WKTWriter.write
class A Alias for Area class.
django.ref.contrib.gis.measure#django.contrib.gis.measure.A
class Area(**kwargs) [source] To initialize an area object, pass in a keyword corresponding to the desired unit attribute name set with desired value. For example, the following creates an area object representing 5 square miles: >>> a = Area(sq_mi=5) __getattr__(unit_att) Returns the area value in units corresponding to the given unit attribute. For example: >>> print(a.sq_km) 12.949940551680001 classmethod unit_attname(unit_name) Returns the area unit attribute name for the given full unit name. For example: >>> Area.unit_attname('Kilometer') 'sq_km'
django.ref.contrib.gis.measure#django.contrib.gis.measure.Area
__getattr__(unit_att)
django.ref.contrib.gis.measure#django.contrib.gis.measure.Area.__getattr__
class D Alias for Distance class.
django.ref.contrib.gis.measure#django.contrib.gis.measure.D
class Distance(**kwargs) [source] To initialize a distance object, pass in a keyword corresponding to the desired unit attribute name set with desired value. For example, the following creates a distance object representing 5 miles: >>> dist = Distance(mi=5) __getattr__(unit_att) Returns the distance value in units corresponding to the given unit attribute. For example: >>> print(dist.km) 8.04672 classmethod unit_attname(unit_name) Returns the distance unit attribute name for the given full unit name. For example: >>> Distance.unit_attname('Mile') 'mi'
django.ref.contrib.gis.measure#django.contrib.gis.measure.Distance
__getattr__(unit_att)
django.ref.contrib.gis.measure#django.contrib.gis.measure.Distance.__getattr__
class LayerMapping(model, data_source, mapping, layer=0, source_srs=None, encoding=None, transaction_mode='commit_on_success', transform=True, unique=True, using='default')
django.ref.contrib.gis.layermapping#django.contrib.gis.utils.LayerMapping
LayerMapping.save(verbose=False, fid_range=False, step=False, progress=False, silent=False, stream=sys.stdout, strict=False)
django.ref.contrib.gis.layermapping#django.contrib.gis.utils.LayerMapping.save
mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False)
django.ref.contrib.gis.ogrinspect#django.contrib.gis.utils.mapping
class FileResponse(open_file, as_attachment=False, filename='', **kwargs) FileResponse is a subclass of StreamingHttpResponse optimized for binary files. It uses wsgi.file_wrapper if provided by the wsgi server, otherwise it streams the file out in small chunks. If as_attachment=True, the Content-Disposition header is set to attachment, which asks the browser to offer the file to the user as a download. Otherwise, a Content-Disposition header with a value of inline (the browser default) will be set only if a filename is available. If open_file doesn’t have a name or if the name of open_file isn’t appropriate, provide a custom file name using the filename parameter. Note that if you pass a file-like object like io.BytesIO, it’s your task to seek() it before passing it to FileResponse. The Content-Length and Content-Type headers are automatically set when they can be guessed from contents of open_file.
django.ref.request-response#django.http.FileResponse
FileResponse.set_headers(open_file) This method is automatically called during the response initialization and set various headers (Content-Length, Content-Type, and Content-Disposition) depending on open_file.
django.ref.request-response#django.http.FileResponse.set_headers
class django.http.Http404
django.topics.http.views#django.http.Http404
class HttpRequest
django.ref.request-response#django.http.HttpRequest
HttpRequest.__iter__() Methods implementing a file-like interface for reading from an HttpRequest instance. This makes it possible to consume an incoming request in a streaming fashion. A common use-case would be to process a big XML payload with an iterative parser without constructing a whole XML tree in memory. Given this standard interface, an HttpRequest instance can be passed directly to an XML parser such as ElementTree: import xml.etree.ElementTree as ET for element in ET.iterparse(request): process(element)
django.ref.request-response#django.http.HttpRequest.__iter__
HttpRequest.accepts(mime_type) Returns True if the request Accept header matches the mime_type argument: >>> request.accepts('text/html') True Most browsers send Accept: */* by default, so this would return True for all content types. Setting an explicit Accept header in API requests can be useful for returning a different content type for those consumers only. See Content negotiation example of using accepts() to return different content to API consumers. If a response varies depending on the content of the Accept header and you are using some form of caching like Django’s cache middleware, you should decorate the view with vary_on_headers('Accept') so that the responses are properly cached.
django.ref.request-response#django.http.HttpRequest.accepts
HttpRequest.body The raw HTTP request body as a bytestring. This is useful for processing data in different ways than conventional HTML forms: binary images, XML payload etc. For processing conventional form data, use HttpRequest.POST. You can also read from an HttpRequest using a file-like interface with HttpRequest.read() or HttpRequest.readline(). Accessing the body attribute after reading the request with either of these I/O stream methods will produce a RawPostDataException.
django.ref.request-response#django.http.HttpRequest.body
HttpRequest.build_absolute_uri(location=None) Returns the absolute URI form of location. If no location is provided, the location will be set to request.get_full_path(). If the location is already an absolute URI, it will not be altered. Otherwise the absolute URI is built using the server variables available in this request. For example: >>> request.build_absolute_uri() 'https://example.com/music/bands/the_beatles/?print=true' >>> request.build_absolute_uri('/bands/') 'https://example.com/bands/' >>> request.build_absolute_uri('https://example2.com/bands/') 'https://example2.com/bands/' Note Mixing HTTP and HTTPS on the same site is discouraged, therefore build_absolute_uri() will always generate an absolute URI with the same scheme the current request has. If you need to redirect users to HTTPS, it’s best to let your web server redirect all HTTP traffic to HTTPS.
django.ref.request-response#django.http.HttpRequest.build_absolute_uri
HttpRequest.content_params A dictionary of key/value parameters included in the CONTENT_TYPE header.
django.ref.request-response#django.http.HttpRequest.content_params
HttpRequest.content_type A string representing the MIME type of the request, parsed from the CONTENT_TYPE header.
django.ref.request-response#django.http.HttpRequest.content_type
HttpRequest.COOKIES A dictionary containing all cookies. Keys and values are strings.
django.ref.request-response#django.http.HttpRequest.COOKIES
HttpRequest.current_app The url template tag will use its value as the current_app argument to reverse().
django.ref.request-response#django.http.HttpRequest.current_app
HttpRequest.encoding A string representing the current encoding used to decode form submission data (or None, which means the DEFAULT_CHARSET setting is used). You can write to this attribute to change the encoding used when accessing the form data. Any subsequent attribute accesses (such as reading from GET or POST) will use the new encoding value. Useful if you know the form data is not in the DEFAULT_CHARSET encoding.
django.ref.request-response#django.http.HttpRequest.encoding
HttpRequest.exception_reporter_class This will be used instead of DEFAULT_EXCEPTION_REPORTER for the current request. See Custom error reports for details.
django.ref.request-response#django.http.HttpRequest.exception_reporter_class
HttpRequest.exception_reporter_filter This will be used instead of DEFAULT_EXCEPTION_REPORTER_FILTER for the current request. See Custom error reports for details.
django.ref.request-response#django.http.HttpRequest.exception_reporter_filter
HttpRequest.FILES A dictionary-like object containing all uploaded files. Each key in FILES is the name from the <input type="file" name="">. Each value in FILES is an UploadedFile. See Managing files for more information. FILES will only contain data if the request method was POST and the <form> that posted to the request had enctype="multipart/form-data". Otherwise, FILES will be a blank dictionary-like object.
django.ref.request-response#django.http.HttpRequest.FILES
HttpRequest.GET A dictionary-like object containing all given HTTP GET parameters. See the QueryDict documentation below.
django.ref.request-response#django.http.HttpRequest.GET
HttpRequest.get_full_path() Returns the path, plus an appended query string, if applicable. Example: "/music/bands/the_beatles/?print=true"
django.ref.request-response#django.http.HttpRequest.get_full_path
HttpRequest.get_full_path_info() Like get_full_path(), but uses path_info instead of path. Example: "/minfo/music/bands/the_beatles/?print=true"
django.ref.request-response#django.http.HttpRequest.get_full_path_info
HttpRequest.get_host() Returns the originating host of the request using information from the HTTP_X_FORWARDED_HOST (if USE_X_FORWARDED_HOST is enabled) and HTTP_HOST headers, in that order. If they don’t provide a value, the method uses a combination of SERVER_NAME and SERVER_PORT as detailed in PEP 3333. Example: "127.0.0.1:8000" Raises django.core.exceptions.DisallowedHost if the host is not in ALLOWED_HOSTS or the domain name is invalid according to RFC 1034/1035. Note The get_host() method fails when the host is behind multiple proxies. One solution is to use middleware to rewrite the proxy headers, as in the following example: class MultipleProxyMiddleware: FORWARDED_FOR_FIELDS = [ 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED_HOST', 'HTTP_X_FORWARDED_SERVER', ] def __init__(self, get_response): self.get_response = get_response def __call__(self, request): """ Rewrites the proxy headers so that only the most recent proxy is used. """ for field in self.FORWARDED_FOR_FIELDS: if field in request.META: if ',' in request.META[field]: parts = request.META[field].split(',') request.META[field] = parts[-1].strip() return self.get_response(request) This middleware should be positioned before any other middleware that relies on the value of get_host() – for instance, CommonMiddleware or CsrfViewMiddleware.
django.ref.request-response#django.http.HttpRequest.get_host
HttpRequest.get_port() Returns the originating port of the request using information from the HTTP_X_FORWARDED_PORT (if USE_X_FORWARDED_PORT is enabled) and SERVER_PORT META variables, in that order.
django.ref.request-response#django.http.HttpRequest.get_port
HttpRequest.get_signed_cookie(key, default=RAISE_ERROR, salt='', max_age=None) Returns a cookie value for a signed cookie, or raises a django.core.signing.BadSignature exception if the signature is no longer valid. If you provide the default argument the exception will be suppressed and that default value will be returned instead. The optional salt argument can be used to provide extra protection against brute force attacks on your secret key. If supplied, the max_age argument will be checked against the signed timestamp attached to the cookie value to ensure the cookie is not older than max_age seconds. For example: >>> request.get_signed_cookie('name') 'Tony' >>> request.get_signed_cookie('name', salt='name-salt') 'Tony' # assuming cookie was set using the same salt >>> request.get_signed_cookie('nonexistent-cookie') ... KeyError: 'nonexistent-cookie' >>> request.get_signed_cookie('nonexistent-cookie', False) False >>> request.get_signed_cookie('cookie-that-was-tampered-with') ... BadSignature: ... >>> request.get_signed_cookie('name', max_age=60) ... SignatureExpired: Signature age 1677.3839159 > 60 seconds >>> request.get_signed_cookie('name', False, max_age=60) False See cryptographic signing for more information.
django.ref.request-response#django.http.HttpRequest.get_signed_cookie
HttpRequest.headers 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) For use in, for example, Django templates, headers can also be looked up using underscores in place of hyphens: {{ request.headers.user_agent }}
django.ref.request-response#django.http.HttpRequest.headers
HttpRequest.is_secure() Returns True if the request is secure; that is, if it was made with HTTPS.
django.ref.request-response#django.http.HttpRequest.is_secure
HttpRequest.META A dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples: CONTENT_LENGTH – The length of the request body (as a string). CONTENT_TYPE – The MIME type of the request body. HTTP_ACCEPT – Acceptable content types for the response. HTTP_ACCEPT_ENCODING – Acceptable encodings for the response. HTTP_ACCEPT_LANGUAGE – Acceptable languages for the response. HTTP_HOST – The HTTP Host header sent by the client. HTTP_REFERER – The referring page, if any. HTTP_USER_AGENT – The client’s user-agent string. QUERY_STRING – The query string, as a single (unparsed) string. REMOTE_ADDR – The IP address of the client. REMOTE_HOST – The hostname of the client. REMOTE_USER – The user authenticated by the web server, if any. REQUEST_METHOD – A string such as "GET" or "POST". SERVER_NAME – The hostname of the server. SERVER_PORT – The port of the server (as a string). With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER. Note that runserver strips all headers with underscores in the name, so you won’t see them in META. This prevents header-spoofing based on ambiguity between underscores and dashes both being normalizing to underscores in WSGI environment variables. It matches the behavior of web servers like Nginx and Apache 2.4+. HttpRequest.headers is a simpler way to access all HTTP-prefixed headers, plus CONTENT_LENGTH and CONTENT_TYPE.
django.ref.request-response#django.http.HttpRequest.META
HttpRequest.method A string representing the HTTP method used in the request. This is guaranteed to be uppercase. For example: if request.method == 'GET': do_something() elif request.method == 'POST': do_something_else()
django.ref.request-response#django.http.HttpRequest.method
HttpRequest.path A string representing the full path to the requested page, not including the scheme, domain, or query string. Example: "/music/bands/the_beatles/"
django.ref.request-response#django.http.HttpRequest.path
HttpRequest.path_info Under some web server configurations, the portion of the URL after the host name is split up into a script prefix portion and a path info portion. The path_info attribute always contains the path info portion of the path, no matter what web server is being used. Using this instead of path can make your code easier to move between test and deployment servers. For example, if the WSGIScriptAlias for your application is set to "/minfo", then path might be "/minfo/music/bands/the_beatles/" and path_info would be "/music/bands/the_beatles/".
django.ref.request-response#django.http.HttpRequest.path_info
HttpRequest.POST A dictionary-like object containing all given HTTP POST parameters, providing that the request contains form data. See the QueryDict documentation below. If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body attribute instead. It’s possible that a request can come in via POST with an empty POST dictionary – if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn’t use if request.POST to check for use of the POST method; instead, use if request.method == "POST" (see HttpRequest.method). POST does not include file-upload information. See FILES.
django.ref.request-response#django.http.HttpRequest.POST
HttpRequest.read(size=None)
django.ref.request-response#django.http.HttpRequest.read
HttpRequest.readline()
django.ref.request-response#django.http.HttpRequest.readline
HttpRequest.readlines()
django.ref.request-response#django.http.HttpRequest.readlines
HttpRequest.resolver_match An instance of ResolverMatch representing the resolved URL. This attribute is only set after URL resolving took place, which means it’s available in all views but not in middleware which are executed before URL resolving takes place (you can use it in process_view() though).
django.ref.request-response#django.http.HttpRequest.resolver_match
HttpRequest.scheme A string representing the scheme of the request (http or https usually).
django.ref.request-response#django.http.HttpRequest.scheme
HttpRequest.session From the SessionMiddleware: A readable and writable, dictionary-like object that represents the current session.
django.ref.request-response#django.http.HttpRequest.session
HttpRequest.site From the CurrentSiteMiddleware: An instance of Site or RequestSite as returned by get_current_site() representing the current site.
django.ref.request-response#django.http.HttpRequest.site
HttpRequest.urlconf This will be used as the root URLconf for the current request, overriding the ROOT_URLCONF setting. See How Django processes a request for details. urlconf can be set to None to revert any changes made by previous middleware and return to using the ROOT_URLCONF.
django.ref.request-response#django.http.HttpRequest.urlconf
HttpRequest.user From the AuthenticationMiddleware: An instance of AUTH_USER_MODEL representing the currently logged-in user. If the user isn’t currently logged in, user will be set to an instance of AnonymousUser. You can tell them apart with is_authenticated, like so: if request.user.is_authenticated: ... # Do something for logged-in users. else: ... # Do something for anonymous users.
django.ref.request-response#django.http.HttpRequest.user
class HttpResponse
django.ref.request-response#django.http.HttpResponse
HttpResponse.__delitem__(header) Deletes the header with the given name. Fails silently if the header doesn’t exist. Case-insensitive.
django.ref.request-response#django.http.HttpResponse.__delitem__
HttpResponse.__getitem__(header) Returns the value for the given header name. Case-insensitive.
django.ref.request-response#django.http.HttpResponse.__getitem__
HttpResponse.__init__(content=b'', content_type=None, status=200, reason=None, charset=None, headers=None) Instantiates an HttpResponse object with the given page content, content type, and headers. content is most commonly an iterator, bytestring, memoryview, or string. Other types will be converted to a bytestring by encoding their string representation. Iterators should return strings or bytestrings and those will be joined together to form the content of the response. content_type is the MIME type optionally completed by a character set encoding and is used to fill the HTTP Content-Type header. If not specified, it is formed by 'text/html' and the DEFAULT_CHARSET settings, by default: "text/html; charset=utf-8". status is the HTTP status code for the response. You can use Python’s http.HTTPStatus for meaningful aliases, such as HTTPStatus.NO_CONTENT. reason is the HTTP response phrase. If not provided, a default phrase will be used. charset is the charset in which the response will be encoded. If not given it will be extracted from content_type, and if that is unsuccessful, the DEFAULT_CHARSET setting will be used. headers is a dict of HTTP headers for the response. Changed in Django 3.2: The headers parameter was added.
django.ref.request-response#django.http.HttpResponse.__init__
HttpResponse.__setitem__(header, value) Sets the given header name to the given value. Both header and value should be strings.
django.ref.request-response#django.http.HttpResponse.__setitem__
HttpResponse.charset A string denoting the charset in which the response will be encoded. If not given at HttpResponse instantiation time, it will be extracted from content_type and if that is unsuccessful, the DEFAULT_CHARSET setting will be used.
django.ref.request-response#django.http.HttpResponse.charset
HttpResponse.close() This method is called at the end of the request directly by the WSGI server.
django.ref.request-response#django.http.HttpResponse.close
HttpResponse.closed True if the response has been closed.
django.ref.request-response#django.http.HttpResponse.closed
HttpResponse.content A bytestring representing the content, encoded from a string if necessary.
django.ref.request-response#django.http.HttpResponse.content
HttpResponse.delete_cookie(key, path='/', domain=None, samesite=None) Deletes the cookie with the given key. Fails silently if the key doesn’t exist. Due to the way cookies work, path and domain should be the same values you used in set_cookie() – otherwise the cookie may not be deleted.
django.ref.request-response#django.http.HttpResponse.delete_cookie
HttpResponse.flush() This method makes an HttpResponse instance a file-like object.
django.ref.request-response#django.http.HttpResponse.flush
HttpResponse.get(header, alternate=None) Returns the value for the given header, or an alternate if the header doesn’t exist.
django.ref.request-response#django.http.HttpResponse.get
HttpResponse.getvalue() Returns the value of HttpResponse.content. This method makes an HttpResponse instance a stream-like object.
django.ref.request-response#django.http.HttpResponse.getvalue
HttpResponse.has_header(header) Returns True or False based on a case-insensitive check for a header with the given name.
django.ref.request-response#django.http.HttpResponse.has_header
HttpResponse.headers New in Django 3.2. A case insensitive, dict-like object that provides an interface to all HTTP headers on the response. See Setting header fields.
django.ref.request-response#django.http.HttpResponse.headers
HttpResponse.items() Acts like dict.items() for HTTP headers on the response.
django.ref.request-response#django.http.HttpResponse.items
HttpResponse.readable() Always False. This method makes an HttpResponse instance a stream-like object.
django.ref.request-response#django.http.HttpResponse.readable
HttpResponse.reason_phrase The HTTP reason phrase for the response. It uses the HTTP standard’s default reason phrases. Unless explicitly set, reason_phrase is determined by the value of status_code.
django.ref.request-response#django.http.HttpResponse.reason_phrase