MCPcopy
hub / github.com/django/django / get

Method get

django/views/generic/list.py:157–179  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

155 """
156
157 def get(self, request, *args, **kwargs):
158 self.object_list = self.get_queryset()
159 allow_empty = self.get_allow_empty()
160
161 if not allow_empty:
162 # When pagination is enabled and object_list is a queryset,
163 # it's better to do a cheap query than to load the unpaginated
164 # queryset in memory.
165 if self.get_paginate_by(self.object_list) is not None and hasattr(
166 self.object_list, "exists"
167 ):
168 is_empty = not self.object_list.exists()
169 else:
170 is_empty = not self.object_list
171 if is_empty:
172 raise Http404(
173 _("Empty list and “%(class_name)s.allow_empty” is False.")
174 % {
175 "class_name": self.__class__.__name__,
176 }
177 )
178 context = self.get_context_data()
179 return self.render_to_response(context)
180
181
182class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):

Callers 2

paginate_querysetMethod · 0.45
_view_wrapperFunction · 0.45

Calls 7

Http404Class · 0.90
get_allow_emptyMethod · 0.80
get_paginate_byMethod · 0.80
get_querysetMethod · 0.45
existsMethod · 0.45
get_context_dataMethod · 0.45
render_to_responseMethod · 0.45

Tested by

no test coverage detected