diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-12-21 17:18:41 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-12-21 17:18:41 +0000 |
| commit | b3d2091681d31bf2a6f8c4a1f9f1fb32393864c8 (patch) | |
| tree | 77dc0ac2b1a1ca14836ced4a79a5ae517dbaf188 /docs | |
| parent | d4ef8414957e8e5db43d396eeb77bac4cf654bf8 (diff) | |
Fixed #12816 -- Added a render() shortcut.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15008 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.3.txt | 5 | ||||
| -rw-r--r-- | docs/topics/http/shortcuts.txt | 64 |
2 files changed, 69 insertions, 0 deletions
diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt index 068670f9f2..d111eaeffb 100644 --- a/docs/releases/1.3.txt +++ b/docs/releases/1.3.txt @@ -215,6 +215,11 @@ requests. These include: making it easier to write simple template tags that require access to template context. + * A new :meth:`~django.shortcuts.render()` shortcut -- an + alternative to :meth:`~django.shortcuts.render_to_response()` + providing a :class:`~django.template.RequestContext` by + default. + .. _HTTPOnly: http://www.owasp.org/index.php/HTTPOnly .. _backwards-incompatible-changes-1.3: diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index 315460e6c3..d99429dbce 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -12,6 +12,70 @@ 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`` +========== + +.. function:: render(request, template[, dictionary][, context_instance][, mimetype]) + + Combines a given template with a given context dictionary and returns an + :class:`~django.http.HttpResponse` object with that rendered text. + + :func:`render()` is the same as a call to + :func:`render_to_response()` with a context_instance argument that + that forces the use of a :class:`RequestContext`. + +Required arguments +------------------ + +``request`` + The request object used to generate this response. + +``template`` + The full name of a template to use or sequence of template names. + +Optional arguments +------------------ + +``dictionary`` + A dictionary of values to add to the template context. By default, this + is an empty dictionary. If a value in the dictionary is callable, the + view will call it just before rendering the template. + +``context_instance`` + The context instance to render the template with. By default, the template + will be rendered with a ``RequestContext`` instance (filled with values from + ``request`` and ```dictionary``). + +``mimetype`` + The MIME type to use for the resulting document. Defaults to the value of + the :setting:`DEFAULT_CONTENT_TYPE` setting. + +Example +------- + +The following example renders the template ``myapp/index.html`` with the +MIME type ``application/xhtml+xml``:: + + from django.shortcuts import render_to_response + + def my_view(request): + # View code here... + return render_to_response('myapp/index.html', {"foo": "bar"}, + mimetype="application/xhtml+xml") + +This example is equivalent to:: + + from django.http import HttpResponse + from django.template import Context, loader + + def my_view(request): + # View code here... + t = loader.get_template('myapp/template.html') + c = RequestContext(request, {'foo': 'bar'}) + return HttpResponse(t.render(c), + mimetype="application/xhtml+xml") + + ``render_to_response`` ====================== |
