Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added django.core.template_loader.render_to_string and django.core.ex…

…tensions.render_to_response. django.core.extensions.load_and_render is deprecated in favor of render_to_response.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@664 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 62f036d67dacf8955946c4cccf7e2d30fa0616ea 1 parent 17418cd
@adrianholovaty adrianholovaty authored
Showing with 19 additions and 10 deletions.
  1. +4 −8 django/core/extensions.py
  2. +15 −2 django/core/template_loader.py
View
12 django/core/extensions.py
@@ -5,14 +5,10 @@
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):
"""
View
17 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.
Please sign in to comment.
Something went wrong with that request. Please try again.