diff --git a/xmodule/x_module.py b/xmodule/x_module.py index 1478d6b9bd6..3df98808169 100644 --- a/xmodule/x_module.py +++ b/xmodule/x_module.py @@ -14,6 +14,7 @@ from opaque_keys.edx.asides import AsideDefinitionKeyV2, AsideUsageKeyV2 from opaque_keys.edx.keys import UsageKey from importlib.resources import files, as_file +from pathlib import Path from web_fragments.fragment import Fragment from webob import Response from webob.multidict import MultiDict @@ -872,11 +873,13 @@ def get_template_dirpaths(cls): """ template_dirpaths = [] template_dirname = cls.get_template_dir() - if template_dirname: - template_path = files(__name__).joinpath(template_dirname) - if template_path.is_dir(): - with as_file(template_path) as resolved_path: - template_dirpaths.append(str(resolved_path)) + package, module_path = __name__.split('.', 1) + module_dir = str(Path(module_path).parent) + file_dirs = files(package).joinpath(module_dir, template_dirname) + + if template_dirname and file_dirs.is_dir(): + with as_file(file_dirs) as path: + template_dirpaths.append(path) custom_template_dir = cls.get_custom_template_dir() if custom_template_dir: