module documentation

This module collects helper functions and classes that "span" multiple levels of MVC. In other words, these functions/classes introduce controlled coupling for convenience's sake.

Function get_list_or_404 Use filter() to return a list of objects, or raise an Http404 exception if the list is empty.
Function get_object_or_404 Use get() to return an object, or raise an Http404 exception if the object does not exist.
Function redirect Return an HttpResponseRedirect to the appropriate URL for the arguments passed.
Function render Return an HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments.
Function resolve_url Return a URL appropriate for the arguments passed.
Function _get_queryset Return a QuerySet or a Manager. Duck typing in action: any class with a `get()` method (for get_object_or_404) or a `filter()` method (for get_list_or_404) might do the job.
def get_list_or_404(klass, *args, **kwargs): (source)

Use filter() to return a list of objects, or raise an Http404 exception if the list is empty. klass may be a Model, Manager, or QuerySet object. All other passed arguments and keyword arguments are used in the filter() query.

def get_object_or_404(klass, *args, **kwargs): (source)

Use get() to return an object, or raise an Http404 exception if the object does not exist. klass may be a Model, Manager, or QuerySet object. All other passed arguments and keyword arguments are used in the get() query. Like with QuerySet.get(), MultipleObjectsReturned is raised if more than one object is found.

def redirect(to, *args, permanent=False, **kwargs): (source)

Return an HttpResponseRedirect to the appropriate URL for the arguments passed. The arguments could be: * A model: the model's `get_absolute_url()` function will be called. * A view name, possibly with arguments: `urls.reverse()` will be used to reverse-resolve the name. * A URL, which will be used as-is for the redirect location. Issues a temporary redirect by default; pass permanent=True to issue a permanent redirect.

def render(request, template_name, context=None, content_type=None, status=None, using=None): (source)

Return an HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments.

def resolve_url(to, *args, **kwargs): (source)

Return a URL appropriate for the arguments passed. The arguments could be: * A model: the model's `get_absolute_url()` function will be called. * A view name, possibly with arguments: `urls.reverse()` will be used to reverse-resolve the name. * A URL, which will be returned as-is.

def _get_queryset(klass): (source)

Return a QuerySet or a Manager. Duck typing in action: any class with a `get()` method (for get_object_or_404) or a `filter()` method (for get_list_or_404) might do the job.