Index: django/template/__init__.py
===================================================================
--- django/template/__init__.py	(revision 5151)
+++ django/template/__init__.py	(working copy)
@@ -99,6 +99,9 @@
 # global list of libraries to load by default for a new parser
 builtins = []
 
+# a boolean for if TEMPLATE_STRING_IF_INVALID contains a format string (%s)
+invalid_var_format_string = '%s' in settings.TEMPLATE_STRING_IF_INVALID
+
 class TemplateSyntaxError(Exception):
     def __str__(self):
         try:
@@ -575,6 +578,8 @@
                 obj = None
             else:
                 if settings.TEMPLATE_STRING_IF_INVALID:
+                    if invalid_var_format_string:
+                        return settings.TEMPLATE_STRING_IF_INVALID % self.var
                     return settings.TEMPLATE_STRING_IF_INVALID
                 else:
                     obj = settings.TEMPLATE_STRING_IF_INVALID
Index: tests/regressiontests/templates/tests.py
===================================================================
--- tests/regressiontests/templates/tests.py	(revision 5151)
+++ tests/regressiontests/templates/tests.py	(working copy)
@@ -586,6 +586,8 @@
             'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''),
             'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'),
             'invalidstr04': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'),
+            'invalidstr05': ('{{ var }}', {}, ('', 'INVALID %s', 'var')),
+            'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', 'INVALID %s', 'var.prop')),
 
             ### MULTILINE #############################################################
 
@@ -737,6 +739,7 @@
 
         # Set TEMPLATE_STRING_IF_INVALID to a known string
         old_invalid = settings.TEMPLATE_STRING_IF_INVALID
+        expected_invalid_str = 'INVALID'
 
         for name, vals in tests:
             install()
@@ -744,6 +747,10 @@
             if isinstance(vals[2], tuple):
                 normal_string_result = vals[2][0]
                 invalid_string_result = vals[2][1]
+                if '%s' in invalid_string_result:
+                    expected_invalid_str = 'INVALID %s'
+                    invalid_string_result = invalid_string_result % vals[2][2]
+                    template.invalid_var_format_string = True
             else:
                 normal_string_result = vals[2]
                 invalid_string_result = vals[2]
@@ -754,7 +761,7 @@
                 activate('en-us')
 
             for invalid_str, result in [('', normal_string_result),
-                                        ('INVALID', invalid_string_result)]:
+                                        (expected_invalid_str, invalid_string_result)]:
                 settings.TEMPLATE_STRING_IF_INVALID = invalid_str
                 try:
                     output = loader.get_template(name).render(template.Context(vals[1]))
@@ -768,6 +775,10 @@
             if 'LANGUAGE_CODE' in vals[1]:
                 deactivate()
 
+            if template.invalid_var_format_string:
+                expected_invalid_str = 'INVALID'
+                template.invalid_var_format_string = False
+
         loader.template_source_loaders = old_template_loaders
         deactivate()
         settings.TEMPLATE_DEBUG = old_td
Index: AUTHORS
===================================================================
--- AUTHORS	(revision 5151)
+++ AUTHORS	(working copy)
@@ -145,7 +145,7 @@
     lerouxb@gmail.com
     Waylan Limberg <waylan@gmail.com>
     limodou
-    mattmcc
+    Matt McClanahan <cardinal@dodds.net>
     Martin Maney <http://www.chipy.org/Martin_Maney>
     masonsimon+django@gmail.com
     Manuzhai
Index: docs/templates_python.txt
===================================================================
--- docs/templates_python.txt	(revision 5151)
+++ docs/templates_python.txt	(working copy)
@@ -212,6 +212,9 @@
 tags, the variable will be interpreted as ``None``. Filters are always
 applied to invalid variables within these template tags.
 
+If TEMPLATE_STRING_IF_INVALID contains a ``'%s'``, it will be replaced with
+the name of the invalid variable.
+
 .. admonition:: For debug purposes only!
 
     While ``TEMPLATE_STRING_IF_INVALID`` can be a useful debugging tool, 
