From 10baac9617154a1a986530cd90c9f4026810c55a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 31 Mar 2024 14:01:58 +0100 Subject: [PATCH] Render page content as template --- content/core.page/test2.md | 2 ++ requirements.txt | 1 + yamdl_playground/core/views.py | 6 ++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/content/core.page/test2.md b/content/core.page/test2.md index f408913..2a5399b 100644 --- a/content/core.page/test2.md +++ b/content/core.page/test2.md @@ -7,3 +7,5 @@ tags: # Heading My content + +You're on page {{ request.path }} diff --git a/requirements.txt b/requirements.txt index 1d2435d..0b6424c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ django git+https://github.com/andrewgodwin/yamdl@8d34d7397f3564a550042e81ea79cca7d2f3777e gunicorn markdown +chrono diff --git a/yamdl_playground/core/views.py b/yamdl_playground/core/views.py index 5bbda87..2fb532f 100644 --- a/yamdl_playground/core/views.py +++ b/yamdl_playground/core/views.py @@ -2,7 +2,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.template import Template, Context def search(request): with connections["default"].cursor() as cursor: @@ -15,4 +15,6 @@ def search(request): def content(request, slug): page = get_object_or_404(Page, slug=slug) - return HttpResponse(page.content, content_type="text/html") + template = Template(page.content) + + return HttpResponse(template.render(Context({"request": request})), content_type="text/html")