utils.cache.get_max_age()

get_max_age(response) [source] Returns the max-age from the response Cache-Control header as an integer (or None if it wasn’t found or wasn’t an integer).

utils.cache.learn_cache_key()

learn_cache_key(request, response, cache_timeout=None, key_prefix=None) [source] Learns what headers to take into account for some request path from the response object. It stores those headers in a global path registry so that later access to that path will know what headers to take into account without building the response object itself. The headers are named in the Vary header of the response, but we want to prevent response generation. The list of headers to use for cache key generation

utils.cache.patch_cache_control()

patch_cache_control(response, **kwargs) [source] This function patches the Cache-Control header by adding all keyword arguments to it. The transformation is as follows: All keyword parameter names are turned to lowercase, and underscores are converted to hyphens. If the value of a parameter is True (exactly True, not just a true value), only the parameter name is added to the header. All other parameters are added with their value, after applying str() to it.

utils.cache.patch_response_headers()

patch_response_headers(response, cache_timeout=None) [source] Adds some useful headers to the given HttpResponse object: ETag Last-Modified Expires Cache-Control Each header is only added if it isn’t already set. cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used by default.

utils.cache.patch_vary_headers()

patch_vary_headers(response, newheaders) [source] Adds (or updates) the Vary header in the given HttpResponse object. newheaders is a list of header names that should be in Vary. Existing headers in Vary aren’t removed.

utils.dateparse.parse_date()

parse_date(value) [source] Parses a string and returns a datetime.date.

utils.dateparse.parse_datetime()

parse_datetime(value) [source] Parses a string and returns a datetime.datetime. UTC offsets are supported; if value describes one, the result’s tzinfo attribute is a FixedOffset instance.

utils.dateparse.parse_duration()

parse_duration(value) [source] Parses a string and returns a datetime.timedelta. Expects data in the format "DD HH:MM:SS.uuuuuu" or as specified by ISO 8601 (e.g. P4DT1H15M20S which is equivalent to 4 1:15:20).

utils.dateparse.parse_time()

parse_time(value) [source] Parses a string and returns a datetime.time. UTC offsets aren’t supported; if value describes one, the result is None.

utils.decorators.decorator_from_middleware()

decorator_from_middleware(middleware_class) [source] Given a middleware class, returns a view decorator. This lets you use middleware functionality on a per-view basis. The middleware is created with no params passed. It assumes middleware that’s compatible with the old style of Django 1.9 and earlier (having methods like process_request(), process_exception(), and process_response()).