#27130: Cannot use Django Templates in Standalone Mode
-------------------------------+--------------------
     Reporter:  AlJohri        |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.10
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Using Django Templates in standalone mode raises a `AppRegistryNotReady`
 error.

 Root Cause: The `get_templatetag_libraries` method in
 `django.template.backends.django.DjangoTemplates` calls the
 `get_installed_libraries` method. The `get_installed_libraries` method
 calls `apps.get_app_configs` which raises a `AppRegistryNotReady` error if
 used in standalone mode.

 Adding a try except around `get_installed_libraries` is a quick fix that
 worked for me.

 {{{#!python
 def get_templatetag_libraries(self, custom_libraries):
     """
     Return a collation of template tag libraries from installed
     applications and the supplied custom_libraries argument.
     """
     try:
         libraries = get_installed_libraries()
     except AppRegistryNotReady:
         libraries = {}
     libraries.update(custom_libraries)
     return libraries
 }}}

 Can you advise if this is a reasonable solution? If so, I can submit a PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/27130>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.8e418f6eb9d977b3cb723a7238d9ae36%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to