From d3c2dd30d606565fc43a78f4209f269e72515b54 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 15 Sep 2007 18:39:44 +0000 Subject: [PATCH] Fixed #5484 -- Documented render_to_string. Thanks, ubernostrum git-svn-id: http://code.djangoproject.com/svn/django/trunk@6307 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/templates_python.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/templates_python.txt b/docs/templates_python.txt index 3399639611..232f54061f 100644 --- a/docs/templates_python.txt +++ b/docs/templates_python.txt @@ -555,6 +555,38 @@ template loaders that come with Django: Django uses the template loaders in order according to the ``TEMPLATE_LOADERS`` setting. It uses each loader until a loader finds a match. +The ``render_to_string()`` shortcut +=================================== + +To cut down on the repetitive nature of loading and rendering +templates, Django provides a shortcut function which largely +automates the process: ``render_to_string()`` in +``django.template.loader``, which loads a template, renders it and +returns the resulting string:: + + from django.template.loader import render_to_string + rendered = render_to_string('my_template.html', { 'foo': 'bar' }) + +The ``render_to_string`` shortcut takes one required argument -- +``template_name``, which should be the name of the template to load +and render -- and two optional arguments:: + + dictionary + A dictionary to be used as variables and values for the + template's context. This can also be passed as the second + positional argument. + + context_instance + An instance of ``Context`` or a subclass (e.g., an instance of + ``RequestContext``) to use as the template's context. This can + also be passed as the third positional argument. + +See also the `render_to_response()`_ shortcut, which calls +``render_to_string`` and feeds the result into an ``HttpResponse`` +suitable for returning directly from a view. + +.. _render_to_response(): ../shortcuts/#render-to-response + Extending the template system =============================