mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Made jinja2 import lazy in django.forms.
Benchmarking shows that about 22% of the startup time for a simple django project was spent importing jinja2, which the project doesn't use. It's reasonable to make this import lazy. This will only affect projects where jinja2 is installed but not used, but given the prevalence of jinja2 that's likely to be many environments (e.g. if Ansible is installed, or the global Python install is used).
This commit is contained in:
parent
e387f191f7
commit
2d2fbc3a70
@ -7,12 +7,6 @@ from django.template.loader import get_template
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
try:
|
||||
from django.template.backends.jinja2 import Jinja2
|
||||
except ImportError:
|
||||
def Jinja2(params):
|
||||
raise ImportError("jinja2 isn't installed")
|
||||
|
||||
ROOT = Path(__file__).parent
|
||||
|
||||
|
||||
@ -58,7 +52,10 @@ class Jinja2(EngineMixin, BaseRenderer):
|
||||
Load Jinja2 templates from the built-in widget templates in
|
||||
django/forms/jinja2 and from apps' 'jinja2' directory.
|
||||
"""
|
||||
backend = Jinja2
|
||||
@cached_property
|
||||
def backend(self):
|
||||
from django.template.backends.jinja2 import Jinja2
|
||||
return Jinja2
|
||||
|
||||
|
||||
class TemplatesSetting(BaseRenderer):
|
||||
|
Loading…
Reference in New Issue
Block a user