Django shortcut functions

Django shortcut functions

Django shortcut functions — Helper functions and classes that “span” multiple levels of MVC.

Django shortcut functions — Introduce controlled coupling for convenience’s sake.


render() method

Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.


redirect() method

Returns an HttpResponseRedirect to the appropriate URL for the arguments passed.


get_object_or_404() method

Calls get() on a given model manager, but it raises Http404 instead of the model’s DoesNotExist exception.


get_list_or_404() method

Returns the result of filter() on a given model manager cast to a list, raising Http404 if the resulting list is empty.

Django shortcut functions — Structure map

Clickable & Draggable!

Django shortcut functions — Related pages: