mirror of
https://github.com/django-components/django-components.git
synced 2025-08-03 22:08:17 +00:00
Automitically load component templates from directory where settings.py files is (old style), and from settings.py parent dir (new style).
This commit is contained in:
parent
373de73787
commit
58c6e476f1
1 changed files with 16 additions and 1 deletions
|
@ -2,10 +2,25 @@
|
|||
Template loader that loads templates from each Django app's "components" directory.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.loaders.filesystem import Loader as FilesystemLoader
|
||||
from django.template.utils import get_app_template_dirs
|
||||
|
||||
|
||||
class Loader(FilesystemLoader):
|
||||
def get_dirs(self):
|
||||
return get_app_template_dirs("components")
|
||||
component_dir = "components"
|
||||
directories = list(get_app_template_dirs(component_dir))
|
||||
settings_path = Path(*settings.SETTINGS_MODULE.split("."))
|
||||
|
||||
if (path := (settings_path / ".." / component_dir).resolve()).is_dir():
|
||||
directories.append(path)
|
||||
|
||||
if (
|
||||
path := (settings_path / ".." / ".." / component_dir).resolve()
|
||||
).is_dir():
|
||||
directories.append(path)
|
||||
|
||||
return directories
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue