当前位置: 首页>>代码示例>>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;未经允许,请勿转载。