Django

Code

Changeset 664

Show
Ignore:
Timestamp:
09/22/05 09:57:05 (3 years ago)
Author:
adrian
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/extensions.py

    r657 r664  
    66from django.utils.httpwrappers import HttpResponse 
    77 
    8 def load_and_render(template_name, dictionary=None, context_instance=None): 
    9     dictionary = dictionary or {} 
    10     t = template_loader.get_template(template_name) 
    11     if context_instance: 
    12         context_instance.update(dictionary) 
    13     else: 
    14         context_instance = Context(dictionary) 
    15     return HttpResponse(t.render(context_instance)) 
     8def render_to_response(*args, **kwargs): 
     9    return HttpResponse(template_loader.render_to_string(*args, **kwargs)) 
     10 
     11load_and_render = render_to_response # For backwards compatibility. 
    1612 
    1713class DjangoContext(Context): 
  • django/trunk/django/core/template_loader.py

    r3 r664  
    1919    """ 
    2020    return template.Template(source) 
     21 
     22def render_to_string(template_name, dictionary=None, context_instance=None): 
     23    """ 
     24    Loads the given template_name and renders it with the given dictionary as 
     25    context. Returns a string. 
     26    """ 
     27    dictionary = dictionary or {} 
     28    t = get_template(template_name) 
     29    if context_instance: 
     30        context_instance.update(dictionary) 
     31    else: 
     32        context_instance = template.Context(dictionary) 
     33    return t.render(context_instance) 
    2134 
    2235def select_template(template_name_list): 
     
    120133    """ 
    121134    Signal that this template extends a parent template. 
    122      
    123     This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)  
     135 
     136    This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) 
    124137    uses the literal value "base" as the name of the parent template to extend, 
    125138    or ``{% entends variable %}`` uses the value of ``variable`` as the name