mixins-simple.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. =============
  2. Simple mixins
  3. =============
  4. ContextMixin
  5. ------------
  6. .. class:: django.views.generic.base.ContextMixin
  7. .. versionadded:: 1.5
  8. **classpath**
  9. ``django.views.generic.base.ContextMixin``
  10. **Methods**
  11. .. method:: get_context_data(**kwargs)
  12. Returns a dictionary representing the template context. The
  13. keyword arguments provided will make up the returned context.
  14. TemplateResponseMixin
  15. ---------------------
  16. .. class:: django.views.generic.base.TemplateResponseMixin
  17. Provides a mechanism to construct a
  18. :class:`~django.template.response.TemplateResponse`, given
  19. suitable context. The template to use is configurable and can be
  20. further customized by subclasses.
  21. **Methods and Attributes**
  22. .. attribute:: response_class
  23. The response class to be returned by ``render_to_response`` method.
  24. Default is
  25. :class:`TemplateResponse <django.template.response.TemplateResponse>`.
  26. The template and context of ``TemplateResponse`` instances can be
  27. altered later (e.g. in
  28. :ref:`template response middleware <template-response-middleware>`).
  29. If you need custom template loading or custom context object
  30. instantiation, create a ``TemplateResponse`` subclass and assign it to
  31. ``response_class``.
  32. .. method:: render_to_response(context, **response_kwargs)
  33. Returns a ``self.response_class`` instance.
  34. If any keyword arguments are provided, they will be
  35. passed to the constructor of the response class.
  36. Calls :meth:`~TemplateResponseMixin.get_template_names()` to obtain the
  37. list of template names that will be searched looking for an existent
  38. template.
  39. .. method:: get_template_names()
  40. Returns a list of template names to search for when rendering the
  41. template.
  42. If :attr:`TemplateResponseMixin.template_name` is specified, the
  43. default implementation will return a list containing
  44. :attr:`TemplateResponseMixin.template_name` (if it is specified).