diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-14 21:09:38 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-14 21:09:38 +0000 |
| commit | e259b8712ad87d1a398d46c593fa81a824041e5d (patch) | |
| tree | 34c29d1f4fb7199fb94e3527d8f8d164aa3d304c /docs | |
| parent | 66e45411017a4526670ba2c4e465c3ca45d55602 (diff) | |
Added stub of docs/shortcuts.txt
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/shortcuts.txt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/docs/shortcuts.txt b/docs/shortcuts.txt new file mode 100644 index 0000000000..2c0dbb5663 --- /dev/null +++ b/docs/shortcuts.txt @@ -0,0 +1,41 @@ +========================= +Django shortcut functions +========================= + +The package ``django.shortcuts`` collects helper functions and classes that +"span" multiple levels of MVC. In other words, these functions/classes +introduce controlled coupling for convenience's sake. + +``render_to_response`` +====================== + +``django.shortcuts.render_to_response`` renders a given template with a given +context dictionary and returns an ``HttpResponse`` object with that rendered +text. + +Example:: + + from django.shortcuts import render_to_response + r = render_to_response('myapp/template.html', {'foo': 'bar'}) + +This example is equivalent to:: + + from django.http import HttpResponse + from django.template import Context, loader + t = loader.get_template('myapp/template.html') + c = Context({'foo': 'bar'}) + r = HttpResponse(t.render(c)) + +``get_object_or_404`` +===================== + +``django.shortcuts.get_object_or_404`` calls ``get()`` on a given model +manager, but it raises ``django.http.Http404`` instead of the model's +``DoesNotExist`` exception. + +``get_list_or_404`` +=================== + +``django.shortcuts.get_list_or_404`` returns the result of ``filter()`` on a +given model manager, raising ``django.http.Http404`` if the resulting list is +empty. |
