I'm running into a problem when I'm trying to use Django's template system 
in a standalone application. Previously, in Django 1.4, I didn't have this 
problem.

As described at configuring the template system in standalone mode 
<https://docs.djangoproject.com/en/1.7/ref/templates/api/#configuring-the-template-system-in-standalone-mode>,
 
I first configure the settings of Django and then call one of the template 
loaders. However, I get an AppRegistryNotReady error:

In [1]: from django.conf import settings

In [2]: settings.configure(**{'TEMPLATE_DIRS': 
('/home/oliver/projects/autodelayv3/templates',), 'TEMPLATE_LOADERS': 
('django.template.loaders.filesystem.Loader',)})

In [3]: from django.template.loader import render_to_string

In [4]: render_to_string('webform.html', {'first_name': 'Oliver'})
---------------------------------------------------------------------------
AppRegistryNotReady                       Traceback (most recent call last)
<ipython-input-4-d2451b904f1a> in <module>()
----> 1 render_to_string('webform.html', {'first_name': 'Oliver'})

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in render_to_string(template_name, dictionary, context_instance, dirs)
    168         t = select_template(template_name, dirs)
    169     else:
--> 170         t = get_template(template_name, dirs)
    171     if not context_instance:
    172         return t.render(Context(dictionary))

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in get_template(template_name, dirs)
    142     handling template inheritance recursively.
    143     """
--> 144     template, origin = find_template(template_name, dirs)
    145     if not hasattr(template, 'render'):
    146         # template needs to be compiled

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in find_template(name, dirs)
    130     for loader in template_source_loaders:
    131         try:
--> 132             source, display_name = loader(name, dirs)
    133             return (source, make_origin(display_name, loader, name, 
dirs))
    134         except TemplateDoesNotExist:

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in __call__(self, template_name, template_dirs)
     42 
     43     def __call__(self, template_name, template_dirs=None):
---> 44         return self.load_template(template_name, template_dirs)
     45 
     46     def load_template(self, template_name, template_dirs=None):

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in load_template(self, template_name, template_dirs)
     48         origin = make_origin(display_name, 
self.load_template_source, template_name, template_dirs)
     49         try:
---> 50             template = get_template_from_string(source, origin, 
template_name)
     51             return template, None
     52         except TemplateDoesNotExist:

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/loader.pyc
 
in get_template_from_string(source, origin, name)
    154     handling template inheritance recursively.
    155     """
--> 156     return Template(source, origin, name)
    157 
    158 

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/base.pyc
 
in __init__(self, template_string, origin, name)
    130         if settings.TEMPLATE_DEBUG and origin is None:
    131             origin = StringOrigin(template_string)
--> 132         self.nodelist = compile_string(template_string, origin)
    133         self.name = name
    134         self.origin = origin

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/base.pyc
 
in compile_string(template_string, origin)
    160     lexer = lexer_class(template_string, origin)
    161     parser = parser_class(lexer.tokenize())
--> 162     return parser.parse()
    163 
    164 

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/base.pyc
 
in parse(self, parse_until)
    288                     self.invalid_block_tag(token, command, 
parse_until)
    289                 try:
--> 290                     compiled_result = compile_func(self, token)
    291                 except TemplateSyntaxError as e:
    292                     if not self.compile_function_error(token, e):

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/defaulttags.pyc
 
in load(parser, token)
   1113             # add the library to the parser
   1114             try:
-> 1115                 lib = get_library(taglib)
   1116                 parser.add_library(lib)
   1117             except InvalidTemplateLibrary as e:

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/base.pyc
 
in get_library(library_name)
   1329     lib = libraries.get(library_name, None)
   1330     if not lib:
-> 1331         templatetags_modules = get_templatetags_modules()
   1332         tried_modules = []
   1333         for module in templatetags_modules:

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/template/base.pyc
 
in get_templatetags_modules()
   1304         templatetags_modules_candidates = ['django.templatetags']
   1305         templatetags_modules_candidates += ['%s.templatetags' % 
app_config.name
-> 1306             for app_config in apps.get_app_configs()]
   1307         for templatetag_module in templatetags_modules_candidates:
   1308             try:

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/apps/registry.pyc
 
in get_app_configs(self)
    135         Imports applications and returns an iterable of app configs.
    136         """
--> 137         self.check_apps_ready()
    138         return self.app_configs.values()
    139 

/home/oliver/.virtualenvs/base/local/lib/python2.7/site-packages/django/apps/registry.pyc
 
in check_apps_ready(self)
    122         """
    123         if not self.apps_ready:
--> 124             raise AppRegistryNotReady("Apps aren't loaded yet.")
    125 
    126     def check_models_ready(self):

AppRegistryNotReady: Apps aren't loaded yet.

In [5]: import django; print(django.get_version())
1.7.1


Sorry for the huge traceback. I'm trying to figure out if anyone else can 
reproduce this problem (I already tested it on LinuxMintDebianEdition and 
Raspbian) or tell me what I'm doing wrong.
The "webform.html" is a regular file under "
/home/oliver/projects/autodelayv3/templates", obviously.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/22ac5905-6876-4063-9c3f-ef1cc13f2c03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to