Django

Code

Changeset 6307

Show
Ignore:
Timestamp:
09/15/07 13:39:44 (1 year ago)
Author:
adrian
Message:

Fixed #5484 -- Documented render_to_string. Thanks, ubernostrum

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/templates_python.txt

    r6159 r6307  
    556556setting. It uses each loader until a loader finds a match. 
    557557 
     558The ``render_to_string()`` shortcut 
     559=================================== 
     560 
     561To cut down on the repetitive nature of loading and rendering 
     562templates, Django provides a shortcut function which largely 
     563automates the process: ``render_to_string()`` in 
     564``django.template.loader``, which loads a template, renders it and 
     565returns the resulting string:: 
     566 
     567    from django.template.loader import render_to_string 
     568    rendered = render_to_string('my_template.html', { 'foo': 'bar' }) 
     569 
     570The ``render_to_string`` shortcut takes one required argument -- 
     571``template_name``, which should be the name of the template to load 
     572and render -- and two optional arguments:: 
     573 
     574    dictionary 
     575        A dictionary to be used as variables and values for the 
     576        template's context. This can also be passed as the second 
     577        positional argument. 
     578 
     579    context_instance 
     580        An instance of ``Context`` or a subclass (e.g., an instance of 
     581        ``RequestContext``) to use as the template's context. This can 
     582        also be passed as the third positional argument. 
     583 
     584See also the `render_to_response()`_ shortcut, which calls 
     585``render_to_string`` and feeds the result into an ``HttpResponse`` 
     586suitable for returning directly from a view. 
     587 
     588.. _render_to_response(): ../shortcuts/#render-to-response 
     589 
    558590Extending the template system 
    559591=============================