Everything you wanted to know
about the Django framework

Класс MultipleObjectTemplateResponseMixin (Django 2.2)

from django.views.generic.list import MultipleObjectTemplateResponseMixin

Mixin for responding with a template and list of objects.

Атрибуты

  Определено в
content_type = None TemplateResponseMixin
response_class = <class 'django.template.response.TemplateResponse'> TemplateResponseMixin
template_engine = None TemplateResponseMixin
template_name = None TemplateResponseMixin
template_name_suffix = '_list' MultipleObjectTemplateResponseMixin

Методы

MultipleObjectTemplateResponseMixin
Return a list of template names to be used for the request. Must return
a list. May not be called if render_to_response is overridden.
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def get_template_names(self):
    """
    Return a list of template names to be used for the request. Must return
    a list. May not be called if render_to_response is overridden.
    """
    try:
        names = super().get_template_names()
    except ImproperlyConfigured:
        # If template_name isn't specified, it's not a problem --
        # we just start with an empty list.
        names = []
    # If the list is a queryset, we'll invent a template name based on the
    # app and model name. This name gets put at the end of the template
    # name list so that user-supplied names override the automatically-
    # generated ones.
    if hasattr(self.object_list, 'model'):
        opts = self.object_list.model._meta
        names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix))
    elif not names:
        raise ImproperlyConfigured(
            "%(cls)s requires either a 'template_name' attribute "
            "or a get_queryset() method that returns a QuerySet." % {
                'cls': self.__class__.__name__,
            }
        )
    return names
TemplateResponseMixin
Return a list of template names to be used for the request. Must return
a list. May not be called if render_to_response() is overridden.
140
141
142
143
144
145
146
147
148
149
150
def get_template_names(self):
    """
    Return a list of template names to be used for the request. Must return
    a list. May not be called if render_to_response() is overridden.
    """
    if self.template_name is None:
        raise ImproperlyConfigured(
            "TemplateResponseMixin requires either a definition of "
            "'template_name' or an implementation of 'get_template_names()'")
    else:
        return [self.template_name]
Return a response, using the `response_class` for this view, with a template rendered with the given context. Pass response_kwargs to the constructor of the response class.
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def render_to_response(self, context, **response_kwargs):
    """
    Return a response, using the `response_class` for this view, with a
    template rendered with the given context.
    Pass response_kwargs to the constructor of the response class.
    """
    response_kwargs.setdefault('content_type', self.content_type)
    return self.response_class(
        request=self.request,
        template=self.get_template_names(),
        context=context,
        using=self.template_engine,
        **response_kwargs
    )
Auth mixins
Auth views
generic
Generic base
Generic dates
Generic detail
Generic edit
Generic list