Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed template library system so that it looks for a module-level v…

…ariable named 'register' rather than the first instance of template.Library it finds

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2fb95f1de699fbc3c39ac83dbf5fabb63af96642 1 parent 2564f34
Adrian Holovaty authored November 27, 2005
12  django/core/template/__init__.py
@@ -890,13 +890,11 @@ def get_library(module_name):
890 890
             mod = __import__(module_name, '', '', [''])
891 891
         except ImportError, e:
892 892
             raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e)
893  
-        for k, v in mod.__dict__.items():
894  
-            if isinstance(v, Library):
895  
-                lib = v
896  
-                libraries[module_name] = lib
897  
-                break
898  
-    if not lib:
899  
-        raise InvalidTemplateLibrary, "Template library %s does not have a Library member" % module_name
  893
+        try:
  894
+            lib = mod.register
  895
+            libraries[module_name] = lib
  896
+        except AttributeError:
  897
+            raise InvalidTemplateLibrary, "Template library %s does not have a variable named 'register'" % module_name
900 898
     return lib
901 899
 
902 900
 def add_to_builtins(module_name):
9  docs/templates_python.txt
@@ -443,14 +443,13 @@ the given Python module name, not the name of the app.
443 443
 Once you've created that Python module, you'll just have to write a bit of
444 444
 Python code, depending on whether you're writing filters or tags.
445 445
 
446  
-To be a valid tag library, the module contain a module-level variable that is a
447  
-``template.Library`` instance, in which all the tags and filters are
448  
-registered. So, near the top of your module, put the following::
  446
+To be a valid tag library, the module contain a module-level variable named
  447
+``register`` that is a ``template.Library`` instance, in which all the tags and
  448
+filters are registered. So, near the top of your module, put the following::
449 449
 
450 450
     from django.core import template
451  
-    register = template.Library()
452 451
 
453  
-Convention is to call this instance ``register``.
  452
+    register = template.Library()
454 453
 
455 454
 .. admonition:: Behind the scenes
456 455
 

0 notes on commit 2fb95f1

Please sign in to comment.
Something went wrong with that request. Please try again.