The error is confusing because my understanding from
[https://docs.djangoproject.com/en/dev/topics/settings/#using-settings-
without-setting-django-settings-module the documentation] is that calling
the following is sufficient before using Django's template code:
{{{
django.conf.settings.configure()
}}}
Here is the stack trace:
{{{
File
"/Users/chris/dev/.virtualenvs/my_package/scripts/../pyelect/htmlgen.py",
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/loader.py", 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/loader.py", 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/loader.py", line 98, in find_template_loader
TemplateLoader = import_string(loader)
File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-
packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File
"/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/importlib/__init__.py",
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/app_directories.py", 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/app_directories.py", 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/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/Users/chris/dev/.virtualenvs/my_package/lib/python3.4/site-
packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24527>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Investigating further, it looks like this is because
`django.template.loaders.app_directories.Loader` is part of the default
`TEMPLATE_LOADERS` setting. But the
[https://docs.djangoproject.com/en/1.7/ref/templates/api/#configuring-the-
template-system-in-standalone-mode documentation for using templates in
standalone] doesn't say this setting needs to be manually set.
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:1>
Comment (by aaugustin):
In addition to configuring the settings, you must call `django.setup()`.
The documentation could be improved.
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:2>
Comment (by cjerdonek):
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.)
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:3>
* component: Uncategorized => Documentation
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:4>
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:5>
* status: new => closed
* resolution: => duplicate
Comment:
Seems to me this is addressed by the docs added in #25156.
--
Ticket URL: <https://code.djangoproject.com/ticket/24527#comment:6>