本文整理匯總了Python中django.template.utils.get_app_template_dirs方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.get_app_template_dirs方法的具體用法?Python utils.get_app_template_dirs怎麽用?Python utils.get_app_template_dirs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.template.utils
的用法示例。
在下文中一共展示了utils.get_app_template_dirs方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: template_dirs
# 需要導入模塊: from django.template import utils [as 別名]
# 或者: from django.template.utils import get_app_template_dirs [as 別名]
def template_dirs(self):
"""
Returns a list of directories to search for templates.
"""
# Immutable return value because it's cached and shared by callers.
template_dirs = tuple(self.dirs)
if self.app_dirs:
template_dirs += get_app_template_dirs(self.app_dirname)
return template_dirs
示例2: get_template_sources
# 需要導入模塊: from django.template import utils [as 別名]
# 或者: from django.template.utils import get_app_template_dirs [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
"""
Returns the absolute paths to "template_name", when appended to each
directory in "template_dirs". Any paths that don't lie inside one of the
template dirs are excluded from the result set, for security reasons.
"""
if not template_dirs:
template_dirs = get_app_template_dirs('templates')
for template_dir in template_dirs:
try:
yield safe_join(template_dir, template_name)
except SuspiciousFileOperation:
# The joined path was located outside of this template_dir
# (it might be inside another one, so this isn't fatal).
pass
示例3: template_dirs
# 需要導入模塊: from django.template import utils [as 別名]
# 或者: from django.template.utils import get_app_template_dirs [as 別名]
def template_dirs(self):
"""
Return a list of directories to search for templates.
"""
# Immutable return value because it's cached and shared by callers.
template_dirs = tuple(self.dirs)
if self.app_dirs:
template_dirs += get_app_template_dirs(self.app_dirname)
return template_dirs
示例4: get_dirs
# 需要導入模塊: from django.template import utils [as 別名]
# 或者: from django.template.utils import get_app_template_dirs [as 別名]
def get_dirs(self):
return get_app_template_dirs('templates')
示例5: list_templates
# 需要導入模塊: from django.template import utils [as 別名]
# 或者: from django.template.utils import get_app_template_dirs [as 別名]
def list_templates(request):
template_dirs = [s for s in get_app_template_dirs('templates') if re.match(r'.*/karrot/.*', s)]
template_names = set()
templates = {}
for directory in template_dirs:
for directory, dirnames, filenames in os.walk(directory):
relative_dir = directory[len(basedir) + 1:]
for filename in filenames:
if re.match(r'.*\.jinja2$', filename) and not re.match(r'.*\.nopreview\.jinja2$', filename):
path = os.path.join(relative_dir, filename)
# strip out anything past the first dot for the name
name = re.sub(r'\..*$', '', os.path.basename(path))
if name != 'template_preview_list':
template_names.add(name)
formats = []
for idx, s in enumerate(['subject', 'text', 'html']):
if os.path.isfile('{}.{}.jinja2'.format(os.path.join(directory, name), s)):
formats.append(s)
elif s == 'text':
formats.append('autotext')
# only include if some formats were defined (even empty ones would end up with autotext...)
if len(formats) > 1:
formats.append('raw')
templates[name] = {
'name': name,
'has_handler': name in dir(handlers),
'formats': formats,
}
return HttpResponse(
render_to_string(
'template_preview_list.jinja2', {'templates': sorted(templates.values(), key=lambda t: t['name'])}
)
)