Added django.core.template_loader.render_to_string and django.core.extensions.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
This commit is contained in:
parent
17418cd982
commit
62f036d67d
|
@ -5,14 +5,10 @@ from django.core.template import Context
|
||||||
from django.conf.settings import DEBUG, INTERNAL_IPS
|
from django.conf.settings import DEBUG, INTERNAL_IPS
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
|
|
||||||
def load_and_render(template_name, dictionary=None, context_instance=None):
|
def render_to_response(*args, **kwargs):
|
||||||
dictionary = dictionary or {}
|
return HttpResponse(template_loader.render_to_string(*args, **kwargs))
|
||||||
t = template_loader.get_template(template_name)
|
|
||||||
if context_instance:
|
load_and_render = render_to_response # For backwards compatibility.
|
||||||
context_instance.update(dictionary)
|
|
||||||
else:
|
|
||||||
context_instance = Context(dictionary)
|
|
||||||
return HttpResponse(t.render(context_instance))
|
|
||||||
|
|
||||||
class DjangoContext(Context):
|
class DjangoContext(Context):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -19,6 +19,19 @@ def get_template_from_string(source):
|
||||||
"""
|
"""
|
||||||
return template.Template(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):
|
def select_template(template_name_list):
|
||||||
"Given a list of template names, returns the first that can be loaded."
|
"Given a list of template names, returns the first that can be loaded."
|
||||||
for template_name in template_name_list:
|
for template_name in template_name_list:
|
||||||
|
|
Loading…
Reference in New Issue