當前位置: 首頁>>代碼示例>>Python>>正文


Python loader.select_template方法代碼示例

本文整理匯總了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)) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:21,代碼來源:static.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:24,代碼來源:views.py

示例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)) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:24,代碼來源:static.py

示例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 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:24,代碼來源:views.py

示例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 
開發者ID:rkhleics,項目名稱:wagtailmenus,代碼行數:23,代碼來源:mixins.py

示例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)) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:25,代碼來源:static.py

示例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)) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:19,代碼來源:static.py

示例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) 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:20,代碼來源:base.py

示例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 
開發者ID:imsweb,項目名稱:django-seeker,代碼行數:22,代碼來源:views.py

示例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 
開發者ID:silverapp,項目名稱:silver,代碼行數:18,代碼來源:base.py

示例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) 
開發者ID:silverapp,項目名稱:silver,代碼行數:19,代碼來源:base.py

示例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. 
開發者ID:amplab,項目名稱:ampcrowd,代碼行數:18,代碼來源:views.py

示例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 
開發者ID:Liweimin0512,項目名稱:ImitationTmall_Django,代碼行數:27,代碼來源:base.py

示例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 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:28,代碼來源:base.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:response.py


注:本文中的django.template.loader.select_template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。