utils.decorators.decorator_from_middleware_with_args()

decorator_from_middleware_with_args(middleware_class) [source] Like decorator_from_middleware, but returns a function that accepts the arguments to be passed to the middleware_class. For example, the cache_page() decorator is created from the CacheMiddleware like this: cache_page = decorator_from_middleware_with_args(CacheMiddleware) @cache_page(3600) def my_view(request): pass

utils.decorators.method_decorator()

method_decorator(decorator, name='') [source] Converts a function decorator into a method decorator. It can be used to decorate methods or classes; in the latter case, name is the name of the method to be decorated and is required. decorator may also be a list or tuple of functions. They are wrapped in reverse order so that the call order is the order in which the functions appear in the list/tuple. See decorating class based views for example usage. Changed in Django 1.9: The ability to de

utils.deprecation.MiddlewareMixin

class django.utils.deprecation.MiddlewareMixin Django provides django.utils.deprecation.MiddlewareMixin to ease creating middleware classes that are compatible with both MIDDLEWARE and the old MIDDLEWARE_CLASSES. All middleware classes included with Django are compatible with both settings. The mixin provides an __init__() method that accepts an optional get_response argument and stores it in self.get_response. The __call__() method: Calls self.process_request(request) (if defined). Calls se

utils.encoding.escape_uri_path()

escape_uri_path(path) [source] Escapes the unsafe characters from the path portion of a Uniform Resource Identifier (URI).

utils.encoding.filepath_to_uri()

filepath_to_uri(path) [source] Convert a file system path to a URI portion that is suitable for inclusion in a URL. The path is assumed to be either UTF-8 or unicode. This method will encode certain characters that would normally be recognized as special characters for URIs. Note that this method does not encode the ‘ character, as it is a valid character within URIs. See encodeURIComponent() JavaScript function for more details. Returns an ASCII string containing the encoded result.

utils.encoding.force_bytes()

force_bytes(s, encoding='utf-8', strings_only=False, errors='strict') [source] Similar to smart_bytes, except that lazy instances are resolved to bytestrings, rather than kept as lazy objects. If strings_only is True, don’t convert (some) non-string-like objects.

utils.encoding.force_str()

force_str(s, encoding='utf-8', strings_only=False, errors='strict') Alias of force_bytes() on Python 2 and force_text() on Python 3. This function always returns a str.

utils.encoding.force_text()

force_text(s, encoding='utf-8', strings_only=False, errors='strict') [source] Similar to smart_text, except that lazy instances are resolved to strings, rather than kept as lazy objects. If strings_only is True, don’t convert (some) non-string-like objects.

utils.encoding.force_unicode()

force_unicode(s, encoding='utf-8', strings_only=False, errors='strict') Historical name of force_text(). Only available under Python 2.

utils.encoding.iri_to_uri()

iri_to_uri(iri) [source] Convert an Internationalized Resource Identifier (IRI) portion to a URI portion that is suitable for inclusion in a URL. This is the algorithm from section 3.1 of RFC 3987#section-3.1. However, since we are assuming input is either UTF-8 or unicode already, we can simplify things a little from the full method. Takes an IRI in UTF-8 bytes and returns ASCII bytes containing the encoded result.