当前位置: 首页>>代码示例>>Python>>正文


Python engines.all方法代码示例

本文整理汇总了Python中django.template.engines.all方法的典型用法代码示例。如果您正苦于以下问题:Python engines.all方法的具体用法?Python engines.all怎么用?Python engines.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.engines的用法示例。


在下文中一共展示了engines.all方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_default

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def get_default():
        """
        Return the first DjangoTemplates backend that's configured, or raise
        ImproperlyConfigured if none are configured.

        This is required for preserving historical APIs that rely on a
        globally available, implicitly configured engine such as:

        >>> from django.template import Context, Template
        >>> template = Template("Hello {{ name }}!")
        >>> context = Context({'name': "world"})
        >>> template.render(context)
        'Hello world!'
        """
        # Since Engine is imported in django.template and since
        # DjangoTemplates is a wrapper around this Engine class,
        # local imports are required to avoid import loops.
        from django.template import engines
        from django.template.backends.django import DjangoTemplates
        for engine in engines.all():
            if isinstance(engine, DjangoTemplates):
                return engine.engine
        raise ImproperlyConfigured('No DjangoTemplates backend is configured.') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:engine.py

示例2: get_default

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def get_default():
        """
        When only one DjangoTemplates backend is configured, returns it.

        Raises ImproperlyConfigured otherwise.

        This is required for preserving historical APIs that rely on a
        globally available, implicitly configured engine such as:

        >>> from django.template import Context, Template
        >>> template = Template("Hello {{ name }}!")
        >>> context = Context({'name': "world"})
        >>> template.render(context)
        'Hello world!'
        """
        # Since Engine is imported in django.template and since
        # DjangoTemplates is a wrapper around this Engine class,
        # local imports are required to avoid import loops.
        from django.template import engines
        from django.template.backends.django import DjangoTemplates
        django_engines = [engine for engine in engines.all()
                          if isinstance(engine, DjangoTemplates)]
        if len(django_engines) == 1:
            # Unwrap the Engine instance inside DjangoTemplates
            return django_engines[0].engine
        elif len(django_engines) == 0:
            raise ImproperlyConfigured(
                "No DjangoTemplates backend is configured.")
        else:
            raise ImproperlyConfigured(
                "Several DjangoTemplates backends are configured. "
                "You must select one explicitly.") 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:34,代码来源:engine.py

示例3: progressive

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def progressive(image_field, alt_text=''):
    """
    Used as a Jinja2 filter, this function returns a safe HTML chunk.

    Usage (in the HTML template):

        {{ obj.image|progressive }}

    :param django.db.models.fields.files.ImageFieldFile image_field: image
    :param str alt_text: str
    :return: a safe HTML template ready to be rendered
    """
    if not isinstance(image_field, ImageFieldFile):
        raise ValueError('"image_field" argument must be an ImageField.')

    for engine in engines.all():
        if isinstance(engine, BaseEngine) and hasattr(engine, 'env'):
            env = engine.env
            if isinstance(env, Environment):
                context = render_progressive_field(image_field, alt_text)
                template = env.get_template(
                    'progressiveimagefield/render_field.html'
                )
                rendered = template.render(**context)
                return Markup(rendered)
    return '' 
开发者ID:manikos,项目名称:django-progressiveimagefield,代码行数:28,代码来源:filters.py

示例4: flatpages_as_templates

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def flatpages_as_templates(cls):
    """
    View decorator:
    Facilitates rendering flat pages as Django templates, including usage of
    tags and the view's context. Performs some magic to capture the specific
    view's custom context and provides a helper function `render_flat_page`.
    """
    context_func_name = 'get_context_data'
    context_func = getattr(cls, context_func_name, None)
    if context_func:
        def _get_context_data_superfunc(self, **kwargs):
            context = context_func(self, **kwargs)
            self._flat_page_context = context
            return context
        setattr(cls, context_func_name, _get_context_data_superfunc)

    def render_flat_page(self, page):
        if not page:
            return ''
        from django.template import engines
        template = engines.all()[0].from_string(page['content'])
        return template.render(
            getattr(self, '_flat_page_context', render_flat_page._view_context),
            self.request)
    cls.render_flat_page = render_flat_page
    cls.render_flat_page._view_context = {}

    return cls 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:30,代码来源:mixins.py

示例5: check_context_processors

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def check_context_processors(app_configs, **kwargs):
    errors = []

    if VERSION < (2, 2):
        # The admin.E404 check has been introduced in the Django 2.2 cycle.
        return errors

    for engine in engines.all():
        if isinstance(engine, DjangoTemplates):
            django_templates_instance = engine.engine
            break
    else:
        django_templates_instance = None

    if django_templates_instance:
        if (
            "django.contrib.messages.context_processors.messages"
            not in django_templates_instance.context_processors
            and "admin.E404" not in settings.SILENCED_SYSTEM_CHECKS
        ):
            errors.append(
                checks.Error(
                    "If using 'user_messages.context_processors.messages'"
                    " instead of the official messages context processor"
                    " you have to add 'admin.E404' to SILENCED_SYSTEM_CHECKS.",
                    id="user_messages.E001",
                )
            )

    return errors 
开发者ID:matthiask,项目名称:django-user-messages,代码行数:32,代码来源:apps.py

示例6: test_backend_import_error

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def test_backend_import_error(self):
        """
        Failing to import a backend keeps raising the original import error
        (#24265).
        """
        with self.assertRaisesMessage(ImportError, "No module named 'raise"):
            engines.all()
        with self.assertRaisesMessage(ImportError, "No module named 'raise"):
            engines.all() 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_utils.py

示例7: test_backend_improperly_configured

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def test_backend_improperly_configured(self):
        """
        Failing to initialize a backend keeps raising the original exception
        (#24265).
        """
        msg = 'app_dirs must not be set when loaders is defined.'
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            engines.all()
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            engines.all() 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_utils.py

示例8: test_backend_names_must_be_unique

# 需要导入模块: from django.template import engines [as 别名]
# 或者: from django.template.engines import all [as 别名]
def test_backend_names_must_be_unique(self):
        msg = (
            "Template engine aliases aren't unique, duplicates: django. Set "
            "a unique NAME for each engine in settings.TEMPLATES."
        )
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            engines.all() 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_utils.py


注:本文中的django.template.engines.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。