本文整理汇总了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', {}))
示例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
示例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)