@@ -130,12 +130,12 @@ def find_template(name, dirs=None):
130130 pass
131131 raise TemplateDoesNotExist (name )
132132
133- def get_template (template_name ):
133+ def get_template (template_name , dirs = None ):
134134 """
135135 Returns a compiled Template object for the given template name,
136136 handling template inheritance recursively.
137137 """
138- template , origin = find_template (template_name )
138+ template , origin = find_template (template_name , dirs )
139139 if not hasattr (template , 'render' ):
140140 # template needs to be compiled
141141 template = get_template_from_string (template , origin , template_name )
@@ -148,7 +148,8 @@ def get_template_from_string(source, origin=None, name=None):
148148 """
149149 return Template (source , origin , name )
150150
151- def render_to_string (template_name , dictionary = None , context_instance = None ):
151+ def render_to_string (template_name , dictionary = None , context_instance = None ,
152+ dirs = None ):
152153 """
153154 Loads the given template_name and renders it with the given dictionary as
154155 context. The template_name may be a string to load a single template using
@@ -157,24 +158,24 @@ def render_to_string(template_name, dictionary=None, context_instance=None):
157158 """
158159 dictionary = dictionary or {}
159160 if isinstance (template_name , (list , tuple )):
160- t = select_template (template_name )
161+ t = select_template (template_name , dirs )
161162 else :
162- t = get_template (template_name )
163+ t = get_template (template_name , dirs )
163164 if not context_instance :
164165 return t .render (Context (dictionary ))
165166 # Add the dictionary to the context stack, ensuring it gets removed again
166167 # to keep the context_instance in the same state it started in.
167168 with context_instance .push (dictionary ):
168169 return t .render (context_instance )
169170
170- def select_template (template_name_list ):
171+ def select_template (template_name_list , dirs = None ):
171172 "Given a list of template names, returns the first that can be loaded."
172173 if not template_name_list :
173174 raise TemplateDoesNotExist ("No template names provided" )
174175 not_found = []
175176 for template_name in template_name_list :
176177 try :
177- return get_template (template_name )
178+ return get_template (template_name , dirs )
178179 except TemplateDoesNotExist as e :
179180 if e .args [0 ] not in not_found :
180181 not_found .append (e .args [0 ])
0 commit comments