#34220: ImportError: cannot import name 'csrf_input_lazy' from partially
initialized module 'django.template.backends.utils'
-------------------------------------+-------------------------------------
Reporter: thommy | Owner: nobody
Type: Bug | Status: new
Component: Template | Version: 4.1
system | Keywords: Jinja2 TemplateView
Severity: Normal | ImportError csrf_input_lazy
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi,
most of the time a TemplateView using Jinja2 is working fine, but
sometimes I get the following exception. I wasn't able to figure out why
it happens:
{{{
ImportError: cannot import name 'csrf_input_lazy' from partially
initialized module 'django.template.backends.utils' (most likely due to a
circular import) (/srv/pydl/env/lib/python3.9/site-
packages/django/template/backends/utils.py)
File "django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 220, in _get_response
response = response.render()
File "django/template/response.py", line 114, in render
self.content = self.rendered_content
File "django/template/response.py", line 92, in rendered_content
return template.render(context, self._request)
File "django/template/backends/jinja2.py", line 65, in render
from .utils import csrf_input_lazy, csrf_token_lazy
}}}
The view looks like this:
{{{
class ScriptView(TemplateView):
"""View for Tcl scripts"""
template_engine = "jinja2"
content_type = "text/x-tcl"
extra_context = {"fqdn": settings.FQDN}
}}}
And it is used like the following:
{{{
path(
"script.tcl",
views.ScriptView.as_view(template_name="script.tcl.j2"),
name="script",
),
}}}
Is it a race condition in conjunction with the Jinja2 template backend or
is TemplateView not supposed to be used like this?
Is it possible to force pre-loading the required modules?
Best regards
Thommy
--
Ticket URL: <https://code.djangoproject.com/ticket/34220>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018533986a69-5c80bbd6-4bec-4f75-86ea-5581a4eb3afa-000000%40eu-central-1.amazonses.com.