Opened 5 years ago

Closed 4 years ago

#24527 closed Bug (duplicate)

Using standalone templates gives confusing error message

Reported by: Chris Jerdonek Owned by: nobody
Component: Documentation Version: 1.7
Severity: Normal Keywords: templates, standalone
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


I'm trying to use Django templates in "standalone" fashion, and I'm getting the following AppRegistryNotReady error at bottom (with version 1.7.7).

The error is confusing because my understanding from the documentation is that calling the following is sufficient before using Django's template code:


Here is the stack trace:

    File "/Users/chris/dev/.virtualenvs/my_package/scripts/../pyelect/", line 171, in render_template
        template = get_template(template_name, dirs=[])
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/template/", line 144, in get_template
        template, origin = find_template(template_name, dirs)
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/template/", line 126, in find_template
        loader = find_template_loader(loader_name)
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/template/", line 98, in find_template_loader
        TemplateLoader = import_string(loader)
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/utils/", line 26, in import_string
        module = import_module(module_path)
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/importlib/", line 109, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
      File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
      File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 1129, in _exec
      File "<frozen importlib._bootstrap>", line 1471, in exec_module
      File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/template/loaders/", line 33, in <module>
        app_template_dirs = calculate_app_template_dirs()
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/template/loaders/", line 21, in calculate_app_template_dirs
        for app_config in apps.get_app_configs():
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/apps/", line 137, in get_app_configs
      File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-packages/django/apps/", line 124, in check_apps_ready
        raise AppRegistryNotReady("Apps aren't loaded yet.")
    django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Change History (6)

comment:1 Changed 5 years ago by Chris Jerdonek

Investigating further, it looks like this is because django.template.loaders.app_directories.Loader is part of the default TEMPLATE_LOADERS setting. But the documentation for using templates in standalone doesn't say this setting needs to be manually set.

comment:2 Changed 5 years ago by Aymeric Augustin

In addition to configuring the settings, you must call django.setup().

The documentation could be improved.

comment:3 Changed 5 years ago by Chris Jerdonek

Strictly speaking, it's possible you might not need to call django.setup(). (I'm pretty sure I was able to get things workings by setting TEMPLATE_LOADERS only to use the file loader.) However, once I started using include I started running into problems again (I believe because that causes get_template() to be called without the dirs argument.)

comment:4 Changed 5 years ago by Tim Graham

Component: UncategorizedDocumentation
Triage Stage: UnreviewedAccepted

comment:5 Changed 4 years ago by James Bennett

Easy pickings: set

comment:6 Changed 4 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Seems to me this is addressed by the docs added in #25156.

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