當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。