Ticket #26410: 26410.diff

File 26410.diff, 2.1 KB (added by Alberto Julio Leal Rivera, 9 years ago)
  • docs/ref/templates/api.txt

    diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
    index 6edc818..66cc38f 100644
    a b they are loaded from.  
    10931093
    10941094        If the template is instantiated directly rather than through a
    10951095        template loader, this is ``None``.
     1096
     1097The ``render_to_string`` shortcut
     1098===================================
     1099
     1100.. function:: loader.render_to_string(template_name, context=None, context_instance=None)
     1101
     1102To cut down on the repetitive nature of loading and rendering
     1103templates, Django provides a shortcut function which largely
     1104automates the process: ``render_to_string()`` in
     1105:mod:`django.template.loader`, which loads a template, renders it and
     1106returns the resulting string::
     1107
     1108    from django.template.loader import render_to_string
     1109    rendered = render_to_string('my_template.html', {'foo': 'bar'})
     1110
     1111The ``render_to_string`` shortcut takes one required argument --
     1112``template_name``, which should be the name of the template to load
     1113and render (or a list of template names, in which case Django will use
     1114the first template in the list that exists) -- and two optional arguments:
     1115
     1116``context``
     1117    A dictionary to be used as variables and values for the
     1118    template's context. This should be passed as the second
     1119    positional argument.
     1120
     1121    .. versionchanged:: 1.8
     1122
     1123       The ``context`` argument used to be called ``dictionary``. That name
     1124       is deprecated in Django 1.8 and will be removed in Django 2.0.
     1125
     1126``context_instance``
     1127    An instance of :class:`~django.template.Context` or a subclass (e.g., an
     1128    instance of :class:`~django.template.RequestContext`) to use as the
     1129    template's context. This can also be passed as the third positional argument.
     1130
     1131    .. deprecated:: 1.8
     1132
     1133       The ``context_instance`` argument is deprecated. Simply use ``context``.
     1134
     1135See also the :func:`~django.shortcuts.render_to_response()` shortcut, which
     1136calls ``render_to_string`` and feeds the result into an :class:`~django.http.HttpResponse`
     1137suitable for returning directly from a view.
Back to Top