class documentation

class CommonMiddleware(MiddlewareMixin): (source)

View In Hierarchy

"Common" middleware for taking care of some basic operations: - Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS - URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings, append missing slashes and/or prepends missing "www."s. - If APPEND_SLASH is set and the initial URL doesn't end with a slash, and it is not found in urlpatterns, form a new URL by appending a slash at the end. If this new URL is found in urlpatterns, return an HTTP redirect to this new URL; otherwise process the initial URL as usual. This behavior can be customized by subclassing CommonMiddleware and overriding the response_redirect_class attribute.

Method get_full_path_with_slash Return the full path of the request with a trailing slash appended.
Method process_request Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW
Method process_response When the status code of the response is 404, it may redirect to a path with an appended slash if should_redirect_with_slash() returns True.
Method should_redirect_with_slash Return True if settings.APPEND_SLASH is True and appending a slash to the request path turns an invalid path into a valid one.

Inherited from MiddlewareMixin:

Async Method __acall__ Async version of __call__ that is swapped in when an async request is running.
Method __call__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Class Variable async_capable Undocumented
Class Variable sync_capable Undocumented
Instance Variable get_response Undocumented
Method _async_check If get_response is a coroutine function, turns us into async mode so a thread is not consumed during a whole request.
Instance Variable _is_coroutine Undocumented
def get_full_path_with_slash(self, request): (source)

Return the full path of the request with a trailing slash appended. Raise a RuntimeError if settings.DEBUG is True and request.method is POST, PUT, or PATCH.

def process_request(self, request): (source)

Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW

def process_response(self, request, response): (source)

When the status code of the response is 404, it may redirect to a path with an appended slash if should_redirect_with_slash() returns True.

def should_redirect_with_slash(self, request): (source)

Return True if settings.APPEND_SLASH is True and appending a slash to the request path turns an invalid path into a valid one.