1.

Explain mixins in Django.

Answer»

A Mixin is a special type of inheritance in PYTHON. It is gaining a big rise in Django / Web Application Development. Mexin can be USED to allow classes in Python to share methods between any class that inherits from that Mixin.

A mixin or mix-in is a class that contains methods for use by other classes without having to be the parent class of those other classes.  Sometimes Mixins are described as "included" rather than "inherited".

Django provides a number of mixins that provide more discrete functionality.  Different type of mixins are -

Simple mixins are -

  • ContextMixin - A dictionary to include in the context and is a convenient way of specifying the simple context in as_view().
  • TemplateResponseMixin - Given a suitable context, TemplateResponseMixin provides a mechanism to construct a TemplateRespons and the template to use is configurable and can be further CUSTOMIZED by a subclass.
  • SingleObjectMixin - SingleObjetMixin provides a mechanism for looking up an object associated with the current HTTP request.
  • SingleObjectTemplateMixin - SingleObjetTemplateMixin performs template base response rendering for VIEW that operate upon a single object instance. 
  • MutlipleObjectMixin - MultipleObjectMixin used to DISPLAY list of objects


Discussion

No Comment Found