summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2013-12-27 11:17:25 +0100
committerFlorian Apolloner <florian@apolloner.eu>2013-12-27 11:17:25 +0100
commit6aa1a316604c063db88a8aa4cd2f25065ae1394c (patch)
tree6a587e47cff531b54a896b00b258a2cdb5312d16
parent025ec2e7fe3f4056835eda94d204ec87901fa11f (diff)
Properly app_template_dirs when INSTALLED_APPS change.
-rw-r--r--django/template/loaders/app_directories.py27
-rw-r--r--django/test/signals.py3
2 files changed, 18 insertions, 12 deletions
diff --git a/django/template/loaders/app_directories.py b/django/template/loaders/app_directories.py
index a2e741b419..587bfb0547 100644
--- a/django/template/loaders/app_directories.py
+++ b/django/template/loaders/app_directories.py
@@ -13,19 +13,22 @@ from django.template.loader import BaseLoader
from django.utils._os import safe_join
from django.utils import six
-# At compile time, cache the directories to search.
-if six.PY2:
- fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
-app_template_dirs = []
-for app_config in apps.get_app_configs():
- template_dir = os.path.join(app_config.path, 'templates')
- if os.path.isdir(template_dir):
- if six.PY2:
- template_dir = template_dir.decode(fs_encoding)
- app_template_dirs.append(template_dir)
-# It won't change, so convert it to a tuple to save memory.
-app_template_dirs = tuple(app_template_dirs)
+def calculate_app_template_dirs():
+ if six.PY2:
+ fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
+ app_template_dirs = []
+ for app_config in apps.get_app_configs():
+ template_dir = os.path.join(app_config.path, 'templates')
+ if os.path.isdir(template_dir):
+ if six.PY2:
+ template_dir = template_dir.decode(fs_encoding)
+ app_template_dirs.append(template_dir)
+ return tuple(app_template_dirs)
+
+
+# At compile time, cache the directories to search.
+app_template_dirs = calculate_app_template_dirs()
class Loader(BaseLoader):
diff --git a/django/test/signals.py b/django/test/signals.py
index 03c40f259d..49bfc64292 100644
--- a/django/test/signals.py
+++ b/django/test/signals.py
@@ -33,6 +33,9 @@ def update_installed_apps(**kwargs):
# Rebuild any AppDirectoriesFinder instance.
from django.contrib.staticfiles.finders import get_finder
get_finder.cache_clear()
+ # Rebuild app_template_dirs cache.
+ from django.template.loaders import app_directories as mod
+ mod.app_template_dirs = mod.calculate_app_template_dirs()
@receiver(setting_changed)