Opened 20 years ago
Closed 20 years ago
#663 closed defect (fixed)
[patch] app_templates-loader broken for testapp
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| 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: | no | UI/UX: | no |
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 by , 20 years ago
comment:2 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
D'oh!
This line
should be
S'ry.