diff --git a/requirements.txt b/requirements.txt index b15f614..e1a469f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ chrono django-debug-toolbar django-jinja jinja2-simple-tags +django-debug-toolbar-template-profiler diff --git a/yamdl_playground/core/models.py b/yamdl_playground/core/models.py index adc921b..07d2372 100644 --- a/yamdl_playground/core/models.py +++ b/yamdl_playground/core/models.py @@ -7,6 +7,7 @@ from pathlib import Path import os.path from django.template import engines from django_jinja.backend import Origin +from django.conf import settings class Tag(models.Model): __yamdl__ = True @@ -75,9 +76,11 @@ class Page(models.Model): if cached_template := self._template_cache.get(self.slug): return cached_template + template_name = Path(self.file_path).relative_to(settings.YAMDL_DIRECTORIES[0]) + template = engines["jinja2"].from_string(self.content) - template.origin = Origin(name=self.slug, template_name=self.slug) - template.name = self.slug + template.origin = Origin(name=self.file_path, template_name=template_name) + template.name = template.template.name = template_name if not self.runtime_render: self._template_cache[self.slug] = template diff --git a/yamdl_playground/settings.py b/yamdl_playground/settings.py index 4de11ff..1c1052e 100644 --- a/yamdl_playground/settings.py +++ b/yamdl_playground/settings.py @@ -239,7 +239,7 @@ if "ENABLE_ADMIN" in os.environ: if "ENABLE_DDT" in os.environ: - INSTALLED_APPS.append("debug_toolbar") + INSTALLED_APPS.extend(["debug_toolbar", "template_profiler_panel"]) MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware") DEBUG_TOOLBAR_CONFIG = { @@ -260,4 +260,5 @@ if "ENABLE_DDT" in os.environ: # 'debug_toolbar.panels.signals.SignalsPanel', # 'debug_toolbar.panels.redirects.RedirectsPanel', # 'debug_toolbar.panels.profiling.ProfilingPanel', + "template_profiler_panel.panels.template.TemplateProfilerPanel" ]