[1.8.x] Refs #24324 -- Fixed get_app_template_dirs() UnicodeDecodeError on Python 2.
The function implemented most of upath(), but skipped the check for
strings that are already unicode.
Backport of bad6280c4e
from master
This commit is contained in:
parent
ba3a7636f1
commit
a1fa0135ec
|
@ -1,12 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import warnings
|
import warnings
|
||||||
from collections import Counter, OrderedDict
|
from collections import Counter, OrderedDict
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils import lru_cache, six
|
from django.utils import lru_cache
|
||||||
|
from django.utils._os import upath
|
||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
from django.utils.deprecation import RemovedInDjango20Warning
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
@ -116,16 +116,12 @@ def get_app_template_dirs(dirname):
|
||||||
dirname is the name of the subdirectory containing templates inside
|
dirname is the name of the subdirectory containing templates inside
|
||||||
installed applications.
|
installed applications.
|
||||||
"""
|
"""
|
||||||
if six.PY2:
|
|
||||||
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
|
|
||||||
template_dirs = []
|
template_dirs = []
|
||||||
for app_config in apps.get_app_configs():
|
for app_config in apps.get_app_configs():
|
||||||
if not app_config.path:
|
if not app_config.path:
|
||||||
continue
|
continue
|
||||||
template_dir = os.path.join(app_config.path, dirname)
|
template_dir = os.path.join(app_config.path, dirname)
|
||||||
if os.path.isdir(template_dir):
|
if os.path.isdir(template_dir):
|
||||||
if six.PY2:
|
template_dirs.append(upath(template_dir))
|
||||||
template_dir = template_dir.decode(fs_encoding)
|
|
||||||
template_dirs.append(template_dir)
|
|
||||||
# Immutable return value because it will be cached and shared by callers.
|
# Immutable return value because it will be cached and shared by callers.
|
||||||
return tuple(template_dirs)
|
return tuple(template_dirs)
|
||||||
|
|
Loading…
Reference in New Issue