summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-04-11 06:48:46 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-04-11 06:48:46 +0000
commitaed032d0ac0f30e7e985f19536ac7a2cd2bc0233 (patch)
treee9c22dc3a3d37077b4a1fbaf5d88320368ae2d6c
parentb579350cd16601a82efd6a497fed07f086371817 (diff)
Fixed #13311 -- Modified the tag library import process so it doesn't mask import errors in the tag library itself. Thanks to amccurdy for the report, and Alex Gaynor for the suggested fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12944 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/__init__.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index 0cd42cf0eb..00949d6e59 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -48,6 +48,7 @@ u'<html><h1>Hello</h1></html>'
>>> t.render(c)
u'<html></html>'
"""
+import imp
import re
from inspect import getargspec
@@ -979,10 +980,19 @@ def import_library(taglib_module):
Verifies that the library contains a 'register' attribute, and
returns that attribute as the representation of the library
"""
+ # We need to be able to tell the difference between a tag library that
+ # doesn't exist, and a tag library with errors in it.
+ # find_module() finds, but doesn't actually load the module requested.
+ # If it raises ImportError, it means the module doesn't exist.
+ # If you then use load_module(), any ImportError is guaranteed to be
+ # an actual import problem with the module.
+ app_path, taglib = taglib_module.rsplit('.',1)
+ app_module = import_module(app_path)
try:
- mod = import_module(taglib_module)
- except ImportError:
+ imp.find_module(taglib, app_module.__path__)
+ except ImportError,e:
return None
+ mod = import_module(taglib_module)
try:
return mod.register
except AttributeError: