summaryrefslogtreecommitdiff
path: root/django/template/loader.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/template/loader.py')
-rw-r--r--django/template/loader.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/django/template/loader.py b/django/template/loader.py
index 03e6f8d49d..45cf5a9d7c 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -87,14 +87,12 @@ def get_template_from_string(source, origin=None, name=None):
"""
return Template(source, origin, name)
-def render_to_string(template_name, dictionary=None, context_instance=None):
+def _render_setup(template_name, dictionary=None, context_instance=None):
"""
- Loads the given template_name and renders it with the given dictionary as
- context. The template_name may be a string to load a single template using
- get_template, or it may be a tuple to use select_template to find one of
- the templates in the list. Returns a string.
+ Common setup code for render_to_string and render_to_iter.
"""
- dictionary = dictionary or {}
+ if dictionary is None:
+ dictionary = {}
if isinstance(template_name, (list, tuple)):
t = select_template(template_name)
else:
@@ -103,7 +101,28 @@ def render_to_string(template_name, dictionary=None, context_instance=None):
context_instance.update(dictionary)
else:
context_instance = Context(dictionary)
- return t.render(context_instance)
+ return t, context_instance
+
+def render_to_string(template_name, dictionary=None, context_instance=None):
+ """
+ Loads the given template_name and renders it with the given dictionary as
+ context. The template_name may be a string to load a single template using
+ get_template, or it may be a tuple to use select_template to find one of
+ the templates in the list. Returns a string.
+ """
+ t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance)
+ return t.render(c)
+
+def render_to_iter(template_name, dictionary=None, context_instance=None):
+ """
+ Loads the given template_name and renders it with the given dictionary as
+ context. The template_name may be a string to load a single template using
+ get_template, or it may be a tuple to use select_template to find one of
+ the templates in the list. Returns a string.
+ """
+ t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance)
+ return t.iter_render(c)
+
def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded."