mirror of https://github.com/django/django.git
Added a get_template_sources generator function to filesystem and app_directories template loaders, so template-loader debugger can hook into it. Refs #892.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c616d869ed
commit
22746d32a5
|
@ -59,7 +59,7 @@ def make_origin(display_name, loader, name, dirs):
|
||||||
def find_template_source(name, dirs=None):
|
def find_template_source(name, dirs=None):
|
||||||
for loader in template_source_loaders:
|
for loader in template_source_loaders:
|
||||||
try:
|
try:
|
||||||
source, display_name = loader(name, dirs)
|
source, display_name = loader(name, dirs)
|
||||||
return (source, make_origin(display_name, loader, name, dirs))
|
return (source, make_origin(display_name, loader, name, dirs))
|
||||||
except TemplateDoesNotExist:
|
except TemplateDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -27,9 +27,12 @@ for app in INSTALLED_APPS:
|
||||||
# It won't change, so convert it to a tuple to save memory.
|
# It won't change, so convert it to a tuple to save memory.
|
||||||
app_template_dirs = tuple(app_template_dirs)
|
app_template_dirs = tuple(app_template_dirs)
|
||||||
|
|
||||||
def load_template_source(template_name, template_dirs=None):
|
def get_template_sources(template_name, template_dirs=None):
|
||||||
for template_dir in app_template_dirs:
|
for template_dir in app_template_dirs:
|
||||||
filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
|
yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
|
||||||
|
|
||||||
|
def load_template_source(template_name, template_dirs=None):
|
||||||
|
for filepath in get_template_sources(template_name, template_dirs):
|
||||||
try:
|
try:
|
||||||
return (open(filepath).read(), filepath)
|
return (open(filepath).read(), filepath)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
|
@ -4,12 +4,15 @@ from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSION
|
||||||
from django.core.template import TemplateDoesNotExist
|
from django.core.template import TemplateDoesNotExist
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def load_template_source(template_name, template_dirs=None):
|
def get_template_sources(template_name, template_dirs=None):
|
||||||
if not template_dirs:
|
if not template_dirs:
|
||||||
template_dirs = TEMPLATE_DIRS
|
template_dirs = TEMPLATE_DIRS
|
||||||
tried = []
|
|
||||||
for template_dir in template_dirs:
|
for template_dir in template_dirs:
|
||||||
filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
|
yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
|
||||||
|
|
||||||
|
def load_template_source(template_name, template_dirs=None):
|
||||||
|
tried = []
|
||||||
|
for filepath in get_template_sources(template_name, template_dirs):
|
||||||
try:
|
try:
|
||||||
return (open(filepath).read(), filepath)
|
return (open(filepath).read(), filepath)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
Loading…
Reference in New Issue