MCPcopy
hub / github.com/django/django / get_default

Method get_default

django/template/engine.py:89–112  ·  view source on GitHub ↗

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.templa

()

Source from the content-addressed store, hash-verified

87 @staticmethod
88 @functools.lru_cache
89 def get_default():
90 """
91 Return the first DjangoTemplates backend that's configured, or raise
92 ImproperlyConfigured if none are configured.
93
94 This is required for preserving historical APIs that rely on a
95 globally available, implicitly configured engine such as:
96
97 >>> from django.template import Context, Template
98 >>> template = Template("Hello {{ name }}!")
99 >>> context = Context({'name': "world"})
100 >>> template.render(context)
101 'Hello world!'
102 """
103 # Since Engine is imported in django.template and since
104 # DjangoTemplates is a wrapper around this Engine class,
105 # local imports are required to avoid import loops.
106 from django.template import engines
107 from django.template.backends.django import DjangoTemplates
108
109 for engine in engines.all():
110 if isinstance(engine, DjangoTemplates):
111 return engine.engine
112 raise ImproperlyConfigured("No DjangoTemplates backend is configured.")
113
114 @cached_property
115 def template_context_processors(self):

Callers 4

get_context_dataMethod · 0.45
get_context_dataMethod · 0.45
get_context_dataMethod · 0.45
__init__Method · 0.45

Calls 2

allMethod · 0.45

Tested by

no test coverage detected