Opened 10 years ago

Closed 10 years ago

#663 closed defect (fixed)

[patch] app_templates-loader broken for testapp

Reported by: Sune Kirkeby <sune.kirkeby@…> Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The app_templates-loader assumes that all application-names have at least one '.' in them, which is wrong for testapp. Also, it should turn probably turn ImportErrors into ImproperlyConfigureds. Short patch in-line here:

=== django/core/template/loaders/app_directories.py
==================================================================
--- django/core/template/loaders/app_directories.py     (revision 2981)
+++ django/core/template/loaders/app_directories.py     (local)
@@ -2,14 +2,24 @@

 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
 from django.core.template import TemplateDoesNotExist
+from django.core.exceptions import ImproperlyConfigured
 import os

 # At compile time, cache the directories to search.
 app_template_dirs = []
 for app in INSTALLED_APPS:
     i = app.rfind('.')
-    m, a = app[:i], app[i+1:]
-    mod = getattr(__import__(m, '', '', [a]), a)
+    if i == -1:
+        m, a = app, None
+    else:
+        m, a = app[:i], app[i+1:]
+    try:
+        if a is None:
+            mod = getattr(__import__(m, '', '', []), a)
+        else:
+            mod = getattr(__import__(m, '', '', [a]), a)
+    except ImportError, e:
+        raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0])
     template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
     if os.path.isdir(template_dir):
         app_template_dirs.append(template_dir)

Change History (2)

comment:1 Changed 10 years ago by anonymous

D'oh!
This line

+            mod = getattr(__import__(m, '', '', []), a)

should be

+            mod = __import__(m, '', '', [])

S'ry.

comment:2 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [985]) Fixed #663 -- app_directories template loader no longer assumes a dot in the app name. Thanks, Sune

Note: See TracTickets for help on using tickets.
Back to Top