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
()
| 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): |
no test coverage detected