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 Jaap Roes, 9 years ago

The dependency on the settings is a side effect of importing template.backends.utils.csrf_input_lazy triggering the the import of middleware.csrf.get_token then utils.cache.patch_vary_headers and finally core.cache.caches.

Moving get_token (and maybe rotate_token) to a new module (maybe django.utils.csrf?) would solve this. get_token is imported from at various places throughout the Django codebase.

comment:2 by Tim Graham, 9 years ago

Could you explain the use case for importing the backend without settings configured?

comment:3 by Aymeric Augustin, 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 Jaap Roes, 9 years ago

Resolution: duplicate
Status: newclosed

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

Note: See TracTickets for help on using tickets.
Back to Top