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


Python Library.from_django方法代碼示例

本文整理匯總了Python中coffin.template.Library.from_django方法的典型用法代碼示例。如果您正苦於以下問題:Python Library.from_django方法的具體用法?Python Library.from_django怎麽用?Python Library.from_django使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coffin.template.Library的用法示例。


在下文中一共展示了Library.from_django方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load_lib

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import from_django [as 別名]
 def _load_lib(lib):
     if not isinstance(lib, CoffinLibrary):
         # If this is only a standard Django library,
         # convert it. This will ensure that Django
         # filters in that library are converted and
         # made available in Jinja.
         lib = CoffinLibrary.from_django(lib)
     extensions.extend(getattr(lib, 'jinja2_extensions', []))
     filters.update(getattr(lib, 'jinja2_filters', {}))
     globals.update(getattr(lib, 'jinja2_globals', {}))
     tests.update(getattr(lib, 'jinja2_tests', {}))
     attrs.update(getattr(lib, 'jinja2_environment_attrs', {}))
開發者ID:desres,項目名稱:coffin,代碼行數:14,代碼來源:common.py

示例2: _get_templatelibs

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import from_django [as 別名]
    def _get_templatelibs(self):
        """Return an iterable of template ``Library`` instances.

        Since we cannot support the {% load %} tag in Jinja, we have to
        register all libraries globally.
        """
        from django.conf import settings
        from django.template import get_library, InvalidTemplateLibrary

        libs = []
        for a in settings.INSTALLED_APPS:
            try:
                path = __import__(a + '.templatetags', {}, {}, ['__file__']).__file__
                path = os.path.dirname(path)  # we now have the templatetags/ directory
            except ImportError:
                pass
            else:
                for f in os.listdir(path):
                    if f == '__init__.py':
                        continue
                    if f.endswith('.py'):
                        try:
                            # TODO: will need updating when #6587 lands
                            # libs.append(get_library(
                            #     "django.templatetags.%s" % os.path.splitext(f)[0]))
                            l = get_library(os.path.splitext(f)[0])
                            if not isinstance(l, CoffinLibrary):
                                # If this is only a standard Django library,
                                # convert it. This will ensure that Django
                                # filters in that library are converted and
                                # made available in Jinja.
                                l = CoffinLibrary.from_django(l)
                            libs.append(l)

                        except InvalidTemplateLibrary:
                            pass
        return libs
開發者ID:HubertD,項目名稱:coffin,代碼行數:39,代碼來源:common.py

示例3: pdb_with_context

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import from_django [as 別名]
        if self.use_pdb:
            pdb_with_context(context)
        else:
            setup_readline_history()
            run_shell(context)
        return ''

@register.tag
def repl(parser, token):
    use_pdb = False
    bits = token.contents.split()
    if len(bits) > 1:
        if bits[1] == 'pdb':
            use_pdb = True
        else:
            raise TemplateSyntaxError('The second argument to the "repl" tag, if present, must be "pdb".')
    return REPLNode(use_pdb)


try:
    from coffin.template import Library as CoffinLibrary
    import coffin.common
except ImportError:
    pass
else:
    # We could simply create a Coffin library in the first place,
    # of course, but this allows us to more easily maintain this
    # change as a fork.
    from template_repl.jinja2_ext import REPLExtension
    register = CoffinLibrary.from_django(register)
    register.tag(REPLExtension)
開發者ID:miracle2k,項目名稱:django-template-repl,代碼行數:33,代碼來源:repl.py


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