If you're looking to reduce load time in your localhost then for most people using cached.Loader
will significantly cut the load time.
Note: you cant use APP_DIRS: True
when loaders are defined.
By default (when DEBUG
is True
), the template
system reads and compiles your templates every time they’re rendered.
While the Django template system is quite fast, the overhead from
reading and compiling templates can add up.
You configure the cached template loader with a list of other loaders
that it should wrap. The wrapped loaders are used to locate unknown
templates when they’re first encountered. The cached loader then
stores the compiled Template in memory. The cached Template instance
is returned for subsequent requests to load the same template.
This loader is automatically enabled if OPTIONS['loaders']
isn’t
specified and OPTIONS['debug']
is False
(the latter option defaults to
the value of DEBUG
).
Add this to your TEMPLATES['OPTIONS']
.
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
),
],
Now your TEMPLATES
settings will look like this.
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': False,
...
'OPTIONS': {
'context_processors': [...]
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'path.to.custom.Loader',
]),
],
},
}]
btw this option is already mentioned with some other options in the speedplane answer.