Index: django/template/loader_tags.py
===================================================================
--- django/template/loader_tags.py	(revision 7317)
+++ django/template/loader_tags.py	(working copy)
@@ -39,10 +39,11 @@
 class ExtendsNode(Node):
     must_be_first = True
 
-    def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
+    def __init__(self, nodelist, parent_name, parent_name_expr, 
+                 template_dirs_expr=None):
         self.nodelist = nodelist
         self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
-        self.template_dirs = template_dirs
+        self.template_dirs_expr = template_dirs_expr
 
     def __repr__(self):
         if self.parent_name_expr:
@@ -53,6 +54,9 @@
         if self.parent_name_expr:
             self.parent_name = self.parent_name_expr.resolve(context)
         parent = self.parent_name
+        template_dirs = None
+        if self.template_dirs_expr:
+            template_dirs = self.template_dirs_expr.resolve(context)
         if not parent:
             error_msg = "Invalid template name in 'extends' tag: %r." % parent
             if self.parent_name_expr:
@@ -61,7 +65,7 @@
         if hasattr(parent, 'render'):
             return parent # parent is a Template object
         try:
-            source, origin = find_template_source(parent, self.template_dirs)
+            source, origin = find_template_source(parent, template_dirs)
         except TemplateDoesNotExist:
             raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
         else:
@@ -93,9 +97,9 @@
         return compiled_parent.render(context)
 
 class ConstantIncludeNode(Node):
-    def __init__(self, template_path):
+    def __init__(self, template_path, dirs=None):
         try:
-            t = get_template(template_path)
+            t = get_template(template_path, dirs)
             self.template = t
         except:
             if settings.TEMPLATE_DEBUG:
@@ -109,13 +113,14 @@
             return ''
 
 class IncludeNode(Node):
-    def __init__(self, template_name):
+    def __init__(self, template_name, dirs=None):
         self.template_name = Variable(template_name)
+        self.dirs = dirs
 
     def render(self, context):
         try:
             template_name = self.template_name.resolve(context)
-            t = get_template(template_name)
+            t = get_template(template_name, dirs)
             return t.render(context)
         except TemplateSyntaxError, e:
             if settings.TEMPLATE_DEBUG:
@@ -153,19 +158,26 @@
     or ``{% extends variable %}`` uses the value of ``variable`` as either the
     name of the parent template to extend (if it evaluates to a string) or as
     the parent tempate itelf (if it evaluates to a Template object).
+    
+    This tag accepts an optional second argument which, if provided and not a
+    variable which is None, will override the settings.TEMPLATE_DIRS value.
+    If provided, it should be a variable which is a list of directories.
     """
     bits = token.contents.split()
-    if len(bits) != 2:
-        raise TemplateSyntaxError, "'%s' takes one argument" % bits[0]
+    if len(bits) != 2 and len(bits) != 3:
+        raise TemplateSyntaxError, "'%s' takes one or two arguments" % bits[0]
     parent_name, parent_name_expr = None, None
+    dirs_expr = None
     if bits[1][0] in ('"', "'") and bits[1][-1] == bits[1][0]:
         parent_name = bits[1][1:-1]
     else:
         parent_name_expr = parser.compile_filter(bits[1])
+    if len(bits) == 3:
+        dirs_expr = parser.compile_filter(bits[2])
     nodelist = parser.parse()
     if nodelist.get_nodes_by_type(ExtendsNode):
         raise TemplateSyntaxError, "'%s' cannot appear more than once in the same template" % bits[0]
-    return ExtendsNode(nodelist, parent_name, parent_name_expr)
+    return ExtendsNode(nodelist, parent_name, parent_name_expr, dirs_expr)
 
 def do_include(parser, token):
     """
@@ -176,12 +188,15 @@
         {% include "foo/some_include" %}
     """
     bits = token.contents.split()
-    if len(bits) != 2:
+    if len(bits) != 2 and len(bits) != 3:
         raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0]
     path = bits[1]
+    dirs_expr = None
+    if len(bits) == 3:
+        dirs_expr = parser.compile_filter(bits[2])
     if path[0] in ('"', "'") and path[-1] == path[0]:
-        return ConstantIncludeNode(path[1:-1])
-    return IncludeNode(bits[1])
+        return ConstantIncludeNode(path[1:-1], dirs_expr)
+    return IncludeNode(bits[1], dirs_expr)
 
 register.tag('block', do_block)
 register.tag('extends', do_extends)
Index: docs/templates.txt
===================================================================
--- docs/templates.txt	(revision 7317)
+++ docs/templates.txt	(working copy)
@@ -646,6 +646,10 @@
      parent template. If the variable evaluates to a ``Template`` object,
      Django will use that object as the parent template.
 
+``{% extends "name" template_paths %}`` works for either of the above two ways,
+but will use the variable ``template_paths`` to provide the list of directories
+in which to search for templates.
+
 See `Template inheritance`_ for more information.
 
 filter
