1- # This module collects helper functions and classes that "span" multiple levels
2- # of MVC. In other words, these functions/classes introduce controlled coupling
3- # for convenience's sake.
1+ """
2+ This module collects helper functions and classes that "span" multiple levels
3+ of MVC. In other words, these functions/classes introduce controlled coupling
4+ for convenience's sake.
5+ """
46
57from django .template import loader
68from django .http import HttpResponse , Http404
79from django .db .models .manager import Manager
810
911def render_to_response (* args , ** kwargs ):
12+ """
13+ Return a HttpResponse whose content is filled with the result of calling
14+ django.template.loader.render_to_string() with the passed arguments.
15+ """
1016 return HttpResponse (loader .render_to_string (* args , ** kwargs ))
1117load_and_render = render_to_response # For backwards compatibility.
1218
1319def get_object_or_404 (klass , * args , ** kwargs ):
20+ """
21+ Use get() to return an object, or raise a Http404 exception if the object
22+ does not exist.
23+
24+ klass may be a Model, Manager, or QuerySet object. All other passed
25+ arguments and keyword arguments are used in the get() query.
26+
27+ Note: Like with get(), an AssertionError will be raised if more than one
28+ object is found.
29+ """
1430 if isinstance (klass , Manager ):
1531 manager = klass
1632 klass = manager .model
@@ -22,6 +38,13 @@ def get_object_or_404(klass, *args, **kwargs):
2238 raise Http404 ('No %s matches the given query.' % klass ._meta .object_name )
2339
2440def get_list_or_404 (klass , * args , ** kwargs ):
41+ """
42+ Use filter() to return a list of objects, or raise a Http404 exception if
43+ the list is empty.
44+
45+ klass may be a Model, Manager, or QuerySet object. All other passed
46+ arguments and keyword arguments are used in the filter() query.
47+ """
2548 if isinstance (klass , Manager ):
2649 manager = klass
2750 else :
0 commit comments