[py3] Fixed egg template loader.
This commit is contained in:
parent
dcf72835e3
commit
2ae58b20ec
|
@ -1,13 +1,15 @@
|
||||||
# Wrapper for loading templates from eggs via pkg_resources.resource_string.
|
# Wrapper for loading templates from eggs via pkg_resources.resource_string.
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pkg_resources import resource_string
|
from pkg_resources import resource_string
|
||||||
except ImportError:
|
except ImportError:
|
||||||
resource_string = None
|
resource_string = None
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.template.base import TemplateDoesNotExist
|
from django.template.base import TemplateDoesNotExist
|
||||||
from django.template.loader import BaseLoader
|
from django.template.loader import BaseLoader
|
||||||
from django.conf import settings
|
from django.utils import six
|
||||||
|
|
||||||
class Loader(BaseLoader):
|
class Loader(BaseLoader):
|
||||||
is_usable = resource_string is not None
|
is_usable = resource_string is not None
|
||||||
|
@ -22,9 +24,12 @@ class Loader(BaseLoader):
|
||||||
pkg_name = 'templates/' + template_name
|
pkg_name = 'templates/' + template_name
|
||||||
for app in settings.INSTALLED_APPS:
|
for app in settings.INSTALLED_APPS:
|
||||||
try:
|
try:
|
||||||
return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
|
resource = resource_string(app, pkg_name)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
continue
|
||||||
|
if not six.PY3:
|
||||||
|
resource = resource.decode(settings.FILE_CHARSET)
|
||||||
|
return (resource, 'egg:%s:%s' % (app, pkg_name))
|
||||||
raise TemplateDoesNotExist(template_name)
|
raise TemplateDoesNotExist(template_name)
|
||||||
|
|
||||||
_loader = Loader()
|
_loader = Loader()
|
||||||
|
|
Loading…
Reference in New Issue