Ticket #4278: loader.diff
File loader.diff, 2.0 KB (added by , 18 years ago) |
---|
-
django/template/loader.py
71 71 pass 72 72 raise TemplateDoesNotExist, name 73 73 74 def get_template(template_name ):74 def get_template(template_name, dirs=None): 75 75 """ 76 76 Returns a compiled Template object for the given template name, 77 77 handling template inheritance recursively. 78 78 """ 79 source, origin = find_template_source(template_name )79 source, origin = find_template_source(template_name, dirs) 80 80 template = get_template_from_string(source, origin, template_name) 81 81 return template 82 82 … … 87 87 """ 88 88 return Template(source, origin, name) 89 89 90 def render_to_string(template_name, dictionary=None, context_instance=None ):90 def render_to_string(template_name, dictionary=None, context_instance=None, dirs=None): 91 91 """ 92 92 Loads the given template_name and renders it with the given dictionary as 93 93 context. The template_name may be a string to load a single template using … … 96 96 """ 97 97 dictionary = dictionary or {} 98 98 if isinstance(template_name, (list, tuple)): 99 t = select_template(template_name )99 t = select_template(template_name, dirs) 100 100 else: 101 t = get_template(template_name )101 t = get_template(template_name, dirs) 102 102 if context_instance: 103 103 context_instance.update(dictionary) 104 104 else: 105 105 context_instance = Context(dictionary) 106 106 return t.render(context_instance) 107 107 108 def select_template(template_name_list ):108 def select_template(template_name_list, dirs=None): 109 109 "Given a list of template names, returns the first that can be loaded." 110 110 for template_name in template_name_list: 111 111 try: 112 return get_template(template_name )112 return get_template(template_name, dirs) 113 113 except TemplateDoesNotExist: 114 114 continue 115 115 # If we get here, none of the templates could be loaded