[Django] #25094: Jinja2 backend requires settings to be configured

4 views
Skip to first unread message

Django

unread,
Jul 9, 2015, 11:45:39 AM7/9/15
to django-...@googlegroups.com
#25094: Jinja2 backend requires settings to be configured
---------------------------------+----------------------------------
Reporter: jaap3 | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: master
Severity: Normal | Keywords: jinja2 cache backend
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25094>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 9, 2015, 11:47:15 AM7/9/15
to django-...@googlegroups.com
#25094: Jinja2 backend requires settings to be configured
-------------------------------------+-------------------------------------

Reporter: jaap3 | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: jinja2 cache | Triage Stage:
backend | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jaap3):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25094#comment:1>

Django

unread,
Jul 9, 2015, 11:59:05 AM7/9/15
to django-...@googlegroups.com
#25094: Jinja2 backend requires settings to be configured
-------------------------------------+-------------------------------------

Reporter: jaap3 | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: jinja2 cache | Triage Stage:
backend | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25094#comment:2>

Django

unread,
Jul 9, 2015, 12:23:16 PM7/9/15
to django-...@googlegroups.com
#25094: Jinja2 backend requires settings to be configured
-------------------------------------+-------------------------------------

Reporter: jaap3 | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: jinja2 cache | Triage Stage:
backend | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25094#comment:3>

Django

unread,
Jul 9, 2015, 3:55:44 PM7/9/15
to django-...@googlegroups.com
#25094: Jinja2 backend requires settings to be configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: nobody
Type: Uncategorized | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: duplicate

Keywords: jinja2 cache | Triage Stage:
backend | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jaap3):

* status: new => closed
* resolution: => duplicate


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25094#comment:4>

Reply all
Reply to author
Forward
0 new messages