Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Fixed egg template loader.

  • Loading branch information...
commit 2ae58b20ec72ce501c91dff8a8fcc8fe40cf5019 1 parent dcf7283
@aaugustin aaugustin authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 django/template/loaders/
13 django/template/loaders/
@@ -1,13 +1,15 @@
# Wrapper for loading templates from eggs via pkg_resources.resource_string.
+from __future__ import unicode_literals
from pkg_resources import resource_string
except ImportError:
resource_string = None
+from django.conf import settings
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
-from django.conf import settings
+from django.utils import six
class Loader(BaseLoader):
is_usable = resource_string is not None
@@ -22,9 +24,12 @@ def load_template_source(self, template_name, template_dirs=None):
pkg_name = 'templates/' + template_name
for app in settings.INSTALLED_APPS:
- return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
- except:
- pass
+ resource = resource_string(app, pkg_name)
+ except Exception:
+ continue
+ if not six.PY3:
+ resource = resource.decode(settings.FILE_CHARSET)
+ return (resource, 'egg:%s:%s' % (app, pkg_name))
raise TemplateDoesNotExist(template_name)
_loader = Loader()
Please sign in to comment.
Something went wrong with that request. Please try again.