本文整理汇总了Python中django.template.loader.select_template方法的典型用法代码示例。如果您正苦于以下问题:Python loader.select_template方法的具体用法?Python loader.select_template怎么用?Python loader.select_template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.loader
的用法示例。
在下文中一共展示了loader.select_template方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: directory_index
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def directory_index(path, fullpath):
try:
t = loader.select_template([
'static/directory_index.html',
'static/directory_index',
])
except TemplateDoesNotExist:
t = Engine().from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
files = []
for f in os.listdir(fullpath):
if not f.startswith('.'):
if os.path.isdir(os.path.join(fullpath, f)):
f += '/'
files.append(f)
c = Context({
'directory': path + '/',
'file_list': files,
})
return HttpResponse(t.render(c))
示例2: render_flatpage
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def render_flatpage(request, f):
"""
Internal interface to the flat page view.
"""
# If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated():
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.path)
if f.template_name:
template = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
else:
template = loader.get_template(DEFAULT_TEMPLATE)
# To avoid having to always use the "|safe" filter in flatpage templates,
# mark the title and content as already safe (since they are raw HTML
# content in the first place).
f.title = mark_safe(f.title)
f.content = mark_safe(f.content)
response = HttpResponse(template.render({'flatpage': f}, request))
return response
示例3: directory_index
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def directory_index(path, fullpath):
try:
t = loader.select_template([
'static/directory_index.html',
'static/directory_index',
])
except TemplateDoesNotExist:
t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
c = Context()
else:
c = {}
files = []
for f in os.listdir(fullpath):
if not f.startswith('.'):
if os.path.isdir(os.path.join(fullpath, f)):
f += '/'
files.append(f)
c.update({
'directory': path + '/',
'file_list': files,
})
return HttpResponse(t.render(c))
示例4: render_flatpage
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def render_flatpage(request, f):
"""
Internal interface to the flat page view.
"""
# If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated:
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.path)
if f.template_name:
template = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
else:
template = loader.get_template(DEFAULT_TEMPLATE)
# To avoid having to always use the "|safe" filter in flatpage templates,
# mark the title and content as already safe (since they are raw HTML
# content in the first place).
f.title = mark_safe(f.title)
f.content = mark_safe(f.content)
response = HttpResponse(template.render({'flatpage': f}, request))
return response
示例5: get_sub_menu_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def get_sub_menu_template(self, level=2):
if not hasattr(self, '_sub_menu_template_cache'):
# Initialise cache for this menu instance
self._sub_menu_template_cache = {}
elif level in self._sub_menu_template_cache:
# Return a cached template instance
return self._sub_menu_template_cache[level]
template_name = self._get_specified_sub_menu_template_name(level)
if template_name:
# A template was specified somehow
template = get_template(template_name)
else:
# A template wasn't specified, so search the filesystem
template = select_template(
self.get_sub_menu_template_names(level)
)
# Cache the template instance before returning
self._sub_menu_template_cache[level] = template
return template
示例6: directory_index
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def directory_index(path, fullpath):
try:
t = loader.select_template([
'static/directory_index.html',
'static/directory_index',
])
except TemplateDoesNotExist:
t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
c = Context()
else:
c = {}
files = []
for f in fullpath.iterdir():
if not f.name.startswith('.'):
url = str(f.relative_to(fullpath))
if f.is_dir():
url += '/'
files.append(url)
c.update({
'directory': path + '/',
'file_list': files,
})
return HttpResponse(t.render(c))
示例7: directory_index
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def directory_index(path, fullpath):
try:
t = loader.select_template(['static/directory_index.html',
'static/directory_index'])
except TemplateDoesNotExist:
t = Template(DEFAULT_DIRECTORY_INDEX_TEMPLATE, name='Default directory index template')
files = []
for f in os.listdir(fullpath):
if not f.startswith('.'):
if os.path.isdir(os.path.join(fullpath, f)):
f += '/'
files.append(f)
c = Context({
'directory' : path + '/',
'file_list' : files,
})
return HttpResponse(t.render(c))
示例8: render
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def render(self, template_name, context):
languages = self.get_languages(context['receiver'])
template = select_template([
'{}.{}.email'.format(template_name, lang)
for lang in languages
])
# Get the actually chosen language from the template name
language = template.template.name.split('.', 2)[-2]
with translation.override(language):
parts = []
for part_type in ('subject', 'txt', 'html'):
context['part_type'] = part_type
parts.append(template.render(context))
context.pop('part_type')
return tuple(parts)
示例9: _find_field_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def _find_field_template(self, field_name):
"""
finds and sets the default template instance for the given field name with the given template.
"""
search_templates = []
if field_name in self.field_templates:
search_templates.append(self.field_templates[field_name])
for _cls in inspect.getmro(self.document):
if issubclass(_cls, dsl.DocType):
search_templates.append('seeker/%s/%s.html' % (_cls._doc_type.name, field_name))
search_templates.append('seeker/column.html')
template = loader.select_template(search_templates)
existing_templates = list(set(self._field_templates.values()))
for existing_template in existing_templates:
#If the template object already exists just re-use the existing one.
if template.template.name == existing_template.template.name:
template = existing_template
break
self._field_templates.update({field_name: template})
return template
示例10: get_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def get_template(self, transaction):
provider = transaction.document.provider
provider_slug = slugify(provider.company or provider.name)
template = select_template([
'forms/{}/{}_transaction_form.html'.format(
self.template_slug,
provider_slug
),
'forms/{}/transaction_form.html'.format(
self.template_slug
),
'forms/transaction_form.html'
])
return template
示例11: get_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def get_template(self, state=None):
provider_state_template = '{provider}/{kind}_{state}_pdf.html'.format(
kind=self.kind, provider=self.provider.slug, state=state).lower()
provider_template = '{provider}/{kind}_pdf.html'.format(
kind=self.kind, provider=self.provider.slug).lower()
generic_state_template = '{kind}_{state}_pdf.html'.format(
kind=self.kind, state=state).lower()
generic_template = '{kind}_pdf.html'.format(
kind=self.kind).lower()
_templates = [provider_state_template, provider_template,
generic_state_template, generic_template]
templates = []
for t in _templates:
templates.append('billing_documents/' + t)
return select_template(templates)
示例12: get_scoped_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def get_scoped_template(crowd_name, template_name, context=None):
base_template_name = os.path.join(crowd_name, 'base.html')
if context is not None:
try:
t = get_template(base_template_name)
except TemplateDoesNotExist:
base_template_name = 'basecrowd/base.html'
context['base_template_name'] = base_template_name
return select_template([
os.path.join(crowd_name, template_name),
os.path.join('basecrowd', template_name)])
# When workers submit assignments, we should send data to this view via AJAX
# before submitting to AMT.
示例13: inclusion_tag
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
def wrap(func):
@functools.wraps(func)
def method(self, context, nodes, *arg, **kwargs):
_dict = func(self, context, nodes, *arg, **kwargs)
from django.template.loader import get_template, select_template
if isinstance(file_name, Template):
t = file_name
elif not isinstance(file_name, basestring) and is_iterable(file_name):
t = select_template(file_name)
else:
t = get_template(file_name)
_dict['autoescape'] = context.autoescape
_dict['use_l10n'] = context.use_l10n
_dict['use_tz'] = context.use_tz
_dict['admin_view'] = context['admin_view']
csrf_token = context.get('csrf_token', None)
if csrf_token is not None:
_dict['csrf_token'] = csrf_token
nodes.append(t.render(_dict))
return method
return wrap
示例14: inclusion_tag
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
def wrap(func):
@functools.wraps(func)
def method(self, context, nodes, *arg, **kwargs):
_dict = func(self, context, nodes, *arg, **kwargs)
from django.template.loader import get_template, select_template
cls_str = str if six.PY3 else basestring
if isinstance(file_name, Template):
t = file_name
elif not isinstance(file_name, cls_str) and is_iterable(file_name):
t = select_template(file_name)
else:
t = get_template(file_name)
_dict['autoescape'] = context.autoescape
_dict['use_l10n'] = context.use_l10n
_dict['use_tz'] = context.use_tz
_dict['admin_view'] = context['admin_view']
csrf_token = context.get('csrf_token', None)
if csrf_token is not None:
_dict['csrf_token'] = csrf_token
nodes.append(t.render(_dict))
return method
return wrap
示例15: resolve_template
# 需要导入模块: from django.template import loader [as 别名]
# 或者: from django.template.loader import select_template [as 别名]
def resolve_template(self, template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
return loader.select_template(template, using=self.using)
elif isinstance(template, six.string_types):
return loader.get_template(template, using=self.using)
else:
return template