Opened 9 years ago
Closed 9 years ago
#25094 closed Uncategorized (duplicate)
Jinja2 backend requires settings to be configured
Reported by: | Jaap Roes | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | jinja2 cache backend |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Importing the Jinja2 backend without configuring settings raises:
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
.
As far I can tell the Jinja2 backend doesn't need a cache backend to be configured.
Change History (4)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Could you explain the use case for importing the backend without settings configured?
comment:3 by , 9 years ago
We're trying to keep as many modules as possible importable without requiring configured settings.
IIRC there was another ticket recently to stop accessing settings at import time when importing django.core.caches
. This is the correct approach. The technique proposed here will fix the symptoms for template.backends.utils
but not for any other module that imports django.core.caches
. I recommend to close this as a duplicate of the other ticket.
comment:4 by , 9 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Closing as a duplicate of #25034.
The use case for me was doing some benchmarking on jinja2 VS the cached template loader. (Pretty similar in performance so far).
The dependency on the settings is a side effect of importing
template.backends.utils.csrf_input_lazy
triggering the the import ofmiddleware.csrf.get_token
thenutils.cache.patch_vary_headers
and finallycore.cache.caches
.Moving
get_token
(and mayberotate_token
) to a new module (maybedjango.utils.csrf
?) would solve this.get_token
is imported from at various places throughout the Django codebase.