django-crispy-forms and django-sekizai and django-jinja2 #24

pannal opened this Issue Mar 5, 2012 · 11 comments


None yet

5 participants

pannal commented Mar 5, 2012


using the above combination of modules results in an error (looks like a circular import on find_template_loader):

(djangocms)cmstest@dev:~/djangocms/project/subproject/toxavis$ python runserver --settings=settings_panni
Traceback (most recent call last):
  File "", line 14, in <module>
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/core/management/", line 438, in execute_manager
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/core/management/", line 379, in execute
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/devserver/management/commands/", line 70, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/core/management/", line 209, in execute
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/translation/", line 100, in activate
    return _trans.activate(language)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/translation/", line 202, in activate
    _active.value = translation(language)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/translation/", line 185, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/translation/", line 162, in _fetch
    app = import_module(appname)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/", line 35, in import_module
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/cms/", line 9, in <module>
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/cms/conf/", line 32, in patch_settings
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/cms/conf/", line 56, in post_patch_check
    if not validate_template(template[0], ['js', 'css']):
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django_sekizai-0.5-py2.6.egg/sekizai/", line 86, in validate_template
    found = get_namespaces(template)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django_sekizai-0.5-py2.6.egg/sekizai/", line 76, in get_namespaces
    compiled_template = get_template(template)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 157, in get_template
    template, origin = find_template(template_name)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 128, in find_template
    loader = find_template_loader(loader_name)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 95, in find_template_loader
    mod = import_module(module)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/", line 35, in import_module
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django_jinja/", line 7, in <module>
    from django_jinja.base import env
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django_jinja/", line 173, in <module>
    env = Environment(**initial_params)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django_jinja/", line 94, in __init__
    filemod = import_module(file_mod_path)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/utils/", line 35, in import_module
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/crispy_forms/templatetags/", line 8, in <module>
    from crispy_forms.helper import FormHelper
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/crispy_forms/", line 4, in <module>
    from utils import render_field
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/crispy_forms/", line 14, in <module>
    default_field_template = get_template("%s/field.html" % TEMPLATE_PACK)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 157, in get_template
    template, origin = find_template(template_name)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 128, in find_template
    loader = find_template_loader(loader_name)
  File "/home/cmstest/djangocms/lib/python2.6/site-packages/django/template/", line 101, in find_template_loader
    raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
django.core.exceptions.ImproperlyConfigured: Error importing template source loader django_jinja.loaders.FileSystemLoader: "'module' object has no attribute 'FileSystemLoader'"



Hi @pannal,

I'm not sure what to say about this stacktrace or whose fault is this out of the 3 apps. Could you please post a link to django-jinja2 project. It looks like the project is failing to load the crispy templates. This might because the paths for them are built dynamically.


pannal commented Mar 12, 2012

Hmm I rather think there is a circular import happening. In the initial phase of django-jinja as the template loader while loading crispy_forms' template tags, another get_template() call is being made, caused by crispy_forms' "default_field_template = get_template("%s/field.html" % TEMPLATE_PACK)", which results in a circular import.

niwinz commented Mar 25, 2012

I think that the problem really lies in the cms module with sekizai module , which tries to load templates in runserver boot time. This causes circular imports on django-cryspy-forms.

I think it is related to this: (django/template/

120 def find_template(name, dirs=None):
121     # Calculate template_source_loaders the first time the function is executed
122     # because putting this logic in the module-level namespace may cause 
123     # circular import errors. See Django ticket #1292.
maraujop commented Apr 3, 2012

Thanks Andrei for stepping by, I didn't know what to say about this issue.

I'm gonna ask Jonas Obrist, the author of django-sekizai to look at this to see if we can find a fix for this issue.

ojii commented Apr 21, 2012

Alright, the issue itself is in the CMS, not sekizai (the CMS just uses code from sekizai to do some heavy lifting).

The easiest solution to this issue will be to set SEKIZAI_IGNORE_VALIDATION to True.

The long term solution will probably be to find a better solution for settings/environment validation in the CMS.


Thanks Jonas for clearing this up.

I'm closing the issue as it doesn't reside in django-crispy-forms.


@maraujop maraujop closed this Apr 22, 2012
ojii commented Apr 22, 2012

Arguably it is partially crispy-forms fault to load templates on module-level in template tags. That might cause other issues with other apps/projects.


I understand. The reason behind module-level loading templates is speeding up rendering for people that don't use template caching. It's something allowed by Django itself for this reason.

niwinz commented Apr 22, 2012

The module-level loading templates is not really a problem, but to satisfy most people, we can use a lazy object:

from django.utils.functional import SimpleLazyObject
default_field_template = SimpleLazyObject(lambda: get_template("%s/field.html" % TEMPLATE_PACK))

Confirmation: django-crispy does not work with django-jinja, because of the
The lazy objects seems a good idea.

@maraujop maraujop added a commit that referenced this issue Jun 9, 2012
@maraujop maraujop Fixing issues with module-level template loading
See #GH-24 and #GH-58

Thanks to @niwibe for proposing this solution. The template gets loaded
only once, while it is lazy loaded, so some loaders don't have problems
with it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment