summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/core/extensions.py12
-rw-r--r--django/core/template_loader.py17
2 files changed, 19 insertions, 10 deletions
diff --git a/django/core/extensions.py b/django/core/extensions.py
index 17e1c76734..6cbd1ebe28 100644
--- a/django/core/extensions.py
+++ b/django/core/extensions.py
@@ -5,14 +5,10 @@ from django.core.template import Context
from django.conf.settings import DEBUG, INTERNAL_IPS
from django.utils.httpwrappers import HttpResponse
-def load_and_render(template_name, dictionary=None, context_instance=None):
- dictionary = dictionary or {}
- t = template_loader.get_template(template_name)
- if context_instance:
- context_instance.update(dictionary)
- else:
- context_instance = Context(dictionary)
- return HttpResponse(t.render(context_instance))
+def render_to_response(*args, **kwargs):
+ return HttpResponse(template_loader.render_to_string(*args, **kwargs))
+
+load_and_render = render_to_response # For backwards compatibility.
class DjangoContext(Context):
"""
diff --git a/django/core/template_loader.py b/django/core/template_loader.py
index 2e2a098a86..c2b41f3743 100644
--- a/django/core/template_loader.py
+++ b/django/core/template_loader.py
@@ -19,6 +19,19 @@ def get_template_from_string(source):
"""
return template.Template(source)
+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. Returns a string.
+ """
+ dictionary = dictionary or {}
+ t = get_template(template_name)
+ if context_instance:
+ context_instance.update(dictionary)
+ else:
+ context_instance = template.Context(dictionary)
+ return t.render(context_instance)
+
def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded."
for template_name in template_name_list:
@@ -119,8 +132,8 @@ def do_block(parser, token):
def do_extends(parser, token):
"""
Signal that this template extends a parent template.
-
- This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
+
+ This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
uses the literal value "base" as the name of the parent template to extend,
or ``{% entends variable %}`` uses the value of ``variable`` as the name
of the parent template to extend.