From 7475d70c95db37892f8c0d01de64350fe984dba7 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 31 Mar 2024 14:20:03 +0100 Subject: [PATCH] Install DDT --- yamdl_playground/core/templates/content.html | 6 ++++++ yamdl_playground/core/utils.py | 4 ++++ yamdl_playground/core/views.py | 7 +++++-- yamdl_playground/settings.py | 8 ++++++-- yamdl_playground/urls.py | 5 +++-- 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 yamdl_playground/core/templates/content.html diff --git a/yamdl_playground/core/templates/content.html b/yamdl_playground/core/templates/content.html new file mode 100644 index 0000000..3bf664b --- /dev/null +++ b/yamdl_playground/core/templates/content.html @@ -0,0 +1,6 @@ + + {{ page.title }} + + + {{ content }} + diff --git a/yamdl_playground/core/utils.py b/yamdl_playground/core/utils.py index 7395799..dd83c67 100644 --- a/yamdl_playground/core/utils.py +++ b/yamdl_playground/core/utils.py @@ -6,3 +6,7 @@ class CustomYamdlLoader(ModelLoader): data["slug"] = file_path.stem super().load_fixture(model_class, data, file_path) + + +def show_debug_toolbar(request): + return True diff --git a/yamdl_playground/core/views.py b/yamdl_playground/core/views.py index 2fb532f..238c736 100644 --- a/yamdl_playground/core/views.py +++ b/yamdl_playground/core/views.py @@ -1,7 +1,7 @@ from .models import Page from django.http import HttpResponse from django.db import connections -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.template import Template, Context def search(request): @@ -17,4 +17,7 @@ def content(request, slug): template = Template(page.content) - return HttpResponse(template.render(Context({"request": request})), content_type="text/html") + return render(request, "content.html", { + "page": page, + "content": template.render(Context({"request": request, "page": page})) + }) diff --git a/yamdl_playground/settings.py b/yamdl_playground/settings.py index ac7f2da..3c4a98d 100644 --- a/yamdl_playground/settings.py +++ b/yamdl_playground/settings.py @@ -34,11 +34,13 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', "yamdl_playground.core", "yamdl", + "debug_toolbar" ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.middleware.common.CommonMiddleware', + "debug_toolbar.middleware.DebugToolbarMiddleware", 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] @@ -54,8 +56,6 @@ TEMPLATES = [ 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', ], }, }, @@ -169,3 +169,7 @@ LOGGING = { }, }, } + +DEBUG_TOOLBAR_CONFIG = { + "SHOW_TOOLBAR_CALLBACK": "yamdl_playground.core.utils.show_debug_toolbar" +} diff --git a/yamdl_playground/urls.py b/yamdl_playground/urls.py index 9e56f8e..5808ffa 100644 --- a/yamdl_playground/urls.py +++ b/yamdl_playground/urls.py @@ -14,10 +14,11 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ -from django.urls import path +from django.urls import path, include from .core import views urlpatterns = [ path("search/", views.search), - path("content//", views.content) + path("content//", views.content), + path("__debug__/", include("debug_toolbar.urls")), ]