Module shortcuts
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.
source linkFunctions
▶ def get_list_or_404(klass, *args, **kwargs) Use filter() to return a list of objects, or raise a 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) Use get() to return an object, or raise a 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.
Reexports
▶ def redirect(to, *args, permanent=False, **kwargs) 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) Return a 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) 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.
Reexports