Skip to content

Commit 3b9ffca

Browse files
feat(core,static,templates): always include internal contrib static and templates\n\n- Add /admin_static mount for internal contrib static files (JS, CSS, images)\n- Always add contrib/templates to template DIRS for all template engines\n- Ensure admin and other internal templates/static are available regardless of user settings\n- Refactor: comments in English for clarity
1 parent a33db86 commit 3b9ffca

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/cotlette/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,24 @@ def include_routers(self):
4949
logger.warning(f"⚠️ '{app_path}.router'")
5050

5151
def include_templates(self):
52-
# Include templates specified by user in SETTINGS
52+
# Connect internal Cotlette templates (e.g., admin templates)
53+
internal_template_dirs = [
54+
os.path.join(self.cotlette_directory, "contrib", "templates")
55+
]
5356
for template in self.settings.TEMPLATES:
54-
template_dirs = template.get("DIRS")
57+
# Add internal templates to user template directories
58+
template_dirs = template.get("DIRS", [])
59+
# Convert relative paths to absolute
5560
template_dirs = [os.path.join(self.settings.BASE_DIR, path) for path in template_dirs]
56-
61+
# Add internal templates if not already present
62+
for internal_dir in internal_template_dirs:
63+
if internal_dir not in template_dirs:
64+
template_dirs.append(internal_dir)
65+
template["DIRS"] = template_dirs
5766
def include_static(self):
5867
# Include framework static files
59-
static_dir = os.path.join(self.cotlette_directory, "static")
60-
self.mount("/static", StaticFiles(directory=static_dir), name="static")
68+
internal_static_dir = os.path.join(self.cotlette_directory, "contrib", "static")
69+
self.mount("/admin_static", StaticFiles(directory=internal_static_dir), name="admin_static")
6170

6271
# Include static files specified by user in SETTINGS
6372
if self.settings.STATIC_URL:

0 commit comments

Comments
 (0)