mixins

The mixins module provides a set of reusable mixin classes that can be added to a View.

class mixins.RequestMixin[source]

Mixin class to provide request parsing behavior.

method[source]

Returns the HTTP method.

This should be used instead of just reading request.method, as it allows the method to be overridden by using a hidden form field on a form POST request.

content_type[source]

Returns the content type header.

This should be used instead of request.META.get('HTTP_CONTENT_TYPE'), as it allows the content type to be overridden by using a hidden form field on a form POST request.

DATA[source]

Parses the request body and returns the data.

Similar to request.POST, except that it handles arbitrary parsers, and also works on methods other than POST (eg PUT).

FILES[source]

Parses the request body and returns the files. Similar to request.FILES, except that it handles arbitrary parsers, and also works on methods other than POST (eg PUT).

class mixins.ResponseMixin[source]

Adds behavior for pluggable Renderers to a views.View class.

Default behavior is to use standard HTTP Accept header content negotiation. Also supports overriding the content type by specifying an _accept= parameter in the URL. Ignores Accept headers from Internet Explorer user agents and uses a sensible browser Accept header instead.

render(response)[source]

Takes a Response object and returns an HttpResponse.

class mixins.AuthMixin[source]

Simple mixin class to add authentication and permission checking to a View class.

authentication = ()

The set of permissions that will be enforced on this view.

Should be a tuple/list of classes as described in the permissions module.

user[source]

Returns the user for the current request, as determined by the set of authentication classes applied to the View.

class mixins.ResourceMixin[source]

Provides request validation and response filtering behavior.

Should be a class as described in the resources module.

The resource is an object that maps a view onto it’s representation on the server.

It provides validation on the content of incoming requests, and filters the object representation into a serializable object for the response.

CONTENT[source]

Returns the cleaned, validated request content.

May raise an response.ErrorResponse with status code 400 (Bad Request).

PARAMS[source]

Returns the cleaned, validated query parameters.

May raise an response.ErrorResponse with status code 400 (Bad Request).

validate_request(data, files=None)[source]

Given the request data and optional files, return the cleaned, validated content. May raise an response.ErrorResponse with status code 400 (Bad Request) on failure.

filter_response(obj)[source]

Given the response content, filter it into a serializable object.

class mixins.InstanceMixin[source]

Mixin class that is used to identify a View class as being the canonical identifier for the resources it is mapped to.

classmethod as_view(**initkwargs)[source]

Store the callable object on the resource class that has been associated with this view.

class mixins.ReadModelMixin[source]

Behavior to read a model instance on GET requests

class mixins.CreateModelMixin[source]

Behavior to create a model instance on POST requests

class mixins.UpdateModelMixin[source]

Behavior to update a model instance on PUT requests

class mixins.DeleteModelMixin[source]

Behavior to delete a model instance on DELETE requests

class mixins.ListModelMixin[source]

Behavior to list a set of model instances on GET requests

Project Versions

Previous topic

compat

Next topic

parsers

This Page