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


Python Engine.get_default方法代码示例

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


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

示例1: check_dependencies

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def check_dependencies(self):
        """
        Check that all things needed to run the admin have been correctly installed.

        The default implementation checks that LogEntry, ContentType and the
        auth context processor are installed.
        """
        from django.contrib.contenttypes.models import ContentType

        if not ContentType._meta.installed:
            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
                                       "your INSTALLED_APPS setting in order to use the admin application.")

        default_template_engine = Engine.get_default()
        if not ('django.contrib.auth.context_processors.auth' in default_template_engine.context_processors or
                'django.core.context_processors.auth' in default_template_engine.context_processors):
            raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
                                       "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") 
开发者ID:stormsha,项目名称:StormOnline,代码行数:20,代码来源:sites.py

示例2: get_template_loaders

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def get_template_loaders():
    """
    Compatibility method to fetch the template loaders.
    Source: https://github.com/django-debug-toolbar/django-debug-toolbar/blob/ece1c2775af108a92a0ef59636266b49e286e916/debug_toolbar/compat.py
    """
    try:
        from django.template.engine import Engine
    except ImportError:  # Django < 1.8
        Engine = None

    if Engine:
        try:
            engine = Engine.get_default()
        except ImproperlyConfigured:
            loaders = []
        else:
            loaders = engine.template_loaders
    else:  # Django < 1.8
        from django.template.loader import find_template_loader
        loaders = [
            find_template_loader(loader_name)
            for loader_name in settings.TEMPLATE_LOADERS]
    return loaders 
开发者ID:arteria,项目名称:django-compat,代码行数:25,代码来源:__init__.py

示例3: check_dependencies

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def check_dependencies(self):
        """
        Check that all things needed to run the admin have been correctly installed.

        The default implementation checks that LogEntry, ContentType and the
        auth context processor are installed.
        """
        from django.contrib.contenttypes.models import ContentType

        if not ContentType._meta.installed:
            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
                                       "your INSTALLED_APPS setting in order to use the admin application.")


        default_template_engine = Engine.get_default()
        if not ('django.contrib.auth.context_processors.auth' in default_template_engine.context_processors or
                'django.core.context_processors.auth' in default_template_engine.context_processors):
            raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
                                       "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") 
开发者ID:Liweimin0512,项目名称:ImitationTmall_Django,代码行数:21,代码来源:sites.py

示例4: check_dependencies

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def check_dependencies(self):
        """
        Check that all things needed to run the admin have been correctly installed.

        The default implementation checks that admin and contenttypes apps are
        installed, as well as the auth context processor.
        """
        if not apps.is_installed('django.contrib.admin'):
            raise ImproperlyConfigured(
                "Put 'django.contrib.admin' in your INSTALLED_APPS "
                "setting in order to use the admin application.")
        if not apps.is_installed('django.contrib.contenttypes'):
            raise ImproperlyConfigured(
                "Put 'django.contrib.contenttypes' in your INSTALLED_APPS "
                "setting in order to use the admin application.")
        try:
            default_template_engine = Engine.get_default()
        except Exception:
            # Skip this non-critical check:
            # 1. if the user has a non-trivial TEMPLATES setting and Django
            #    can't find a default template engine
            # 2. if anything goes wrong while loading template engines, in
            #    order to avoid raising an exception from a confusing location
            # Catching ImproperlyConfigured suffices for 1. but 2. requires
            # catching all exceptions.
            pass
        else:
            if ('django.contrib.auth.context_processors.auth'
                    not in default_template_engine.context_processors):
                raise ImproperlyConfigured(
                    "Enable 'django.contrib.auth.context_processors.auth' "
                    "in your TEMPLATES setting in order to use the admin "
                    "application.") 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:35,代码来源:sites.py

示例5: get_context_data

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def get_context_data(self, **kwargs):
        template = self.kwargs['template']
        templates = []
        try:
            default_engine = Engine.get_default()
        except ImproperlyConfigured:
            # Non-trivial TEMPLATES settings aren't supported (#24125).
            pass
        else:
            # This doesn't account for template loaders (#24128).
            for index, directory in enumerate(default_engine.dirs):
                template_file = os.path.join(directory, template)
                templates.append({
                    'file': template_file,
                    'exists': os.path.exists(template_file),
                    'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '',
                    'order': index,
                })
        kwargs.update({
            'name': template,
            'templates': templates,
        })
        return super(TemplateDetailView, self).get_context_data(**kwargs)


####################
# Helper functions #
#################### 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:views.py

示例6: check_dependencies

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def check_dependencies(**kwargs):
    """
    Check that the admin's dependencies are correctly installed.
    """
    errors = []
    # contrib.contenttypes must be installed.
    if not apps.is_installed('django.contrib.contenttypes'):
        missing_app = checks.Error(
            "'django.contrib.contenttypes' must be in INSTALLED_APPS in order "
            "to use the admin application.",
            id="admin.E401",
        )
        errors.append(missing_app)
    # The auth context processor must be installed if using the default
    # authentication backend.
    try:
        default_template_engine = Engine.get_default()
    except Exception:
        # Skip this non-critical check:
        # 1. if the user has a non-trivial TEMPLATES setting and Django
        #    can't find a default template engine
        # 2. if anything goes wrong while loading template engines, in
        #    order to avoid raising an exception from a confusing location
        # Catching ImproperlyConfigured suffices for 1. but 2. requires
        # catching all exceptions.
        pass
    else:
        if ('django.contrib.auth.context_processors.auth'
                not in default_template_engine.context_processors and
                'django.contrib.auth.backends.ModelBackend' in settings.AUTHENTICATION_BACKENDS):
            missing_template = checks.Error(
                "'django.contrib.auth.context_processors.auth' must be in "
                "TEMPLATES in order to use the admin application.",
                id="admin.E402"
            )
            errors.append(missing_template)
    return errors 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:39,代码来源:checks.py

示例7: get_template_source

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def get_template_source(name, dirs=None):
    """Retrieves the template's source contents.

    :param name: Template's filename, as passed to the template loader.
    :param dirs: list of directories to optionally override the defaults.
    :return: tuple including file contents and file path.
    """
    loaders = []
    for loader in Engine.get_default().template_loaders:
        # The cached loader includes the actual loaders underneath
        if hasattr(loader, "loaders"):
            loaders.extend(loader.loaders)
        else:
            loaders.append(loader)

    for loader in loaders:
        for template_dir in loader.get_dirs():
            try:
                filename = safe_join(template_dir, name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            try:
                with open(filename, encoding=loader.engine.file_charset) as fp:
                    return fp.read()
            except FileNotFoundError:
                continue

    raise TemplateDoesNotExist(name) 
开发者ID:evernote,项目名称:zing,代码行数:33,代码来源:templates.py

示例8: get_context_data

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def get_context_data(self, **kwargs):
        tags = []
        try:
            engine = Engine.get_default()
        except ImproperlyConfigured:
            # Non-trivial TEMPLATES settings aren't supported (#24125).
            pass
        else:
            app_libs = sorted(engine.template_libraries.items())
            builtin_libs = [('', lib) for lib in engine.template_builtins]
            for module_name, library in builtin_libs + app_libs:
                for tag_name, tag_func in library.tags.items():
                    title, body, metadata = utils.parse_docstring(tag_func.__doc__)
                    if title:
                        title = utils.parse_rst(title, 'tag', _('tag:') + tag_name)
                    if body:
                        body = utils.parse_rst(body, 'tag', _('tag:') + tag_name)
                    for key in metadata:
                        metadata[key] = utils.parse_rst(metadata[key], 'tag', _('tag:') + tag_name)
                    tag_library = module_name.split('.')[-1]
                    tags.append({
                        'name': tag_name,
                        'title': title,
                        'body': body,
                        'meta': metadata,
                        'library': tag_library,
                    })
        kwargs.update({'tags': tags})
        return super(TemplateTagIndexView, self).get_context_data(**kwargs) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:31,代码来源:views.py

示例9: test_no_engines_configured

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def test_no_engines_configured(self):
        msg = 'No DjangoTemplates backend is configured.'
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            Engine.get_default() 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_engine.py

示例10: test_single_engine_configured

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def test_single_engine_configured(self):
        self.assertEqual(Engine.get_default().file_charset, 'abc') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:test_engine.py

示例11: test_multiple_engines_configured

# 需要导入模块: from django.template.engine import Engine [as 别名]
# 或者: from django.template.engine.Engine import get_default [as 别名]
def test_multiple_engines_configured(self):
        self.assertEqual(Engine.get_default().file_charset, 'abc') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:test_engine.py


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