1
Fork 0

Render page content as template

This commit is contained in:
Jake Howard 2024-03-31 14:01:58 +01:00
parent ff90e8422b
commit 10baac9617
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 7 additions and 2 deletions

View file

@ -7,3 +7,5 @@ tags:
# Heading # Heading
My content My content
You're on page {{ request.path }}

View file

@ -2,3 +2,4 @@ django
git+https://github.com/andrewgodwin/yamdl@8d34d7397f3564a550042e81ea79cca7d2f3777e git+https://github.com/andrewgodwin/yamdl@8d34d7397f3564a550042e81ea79cca7d2f3777e
gunicorn gunicorn
markdown markdown
chrono

View file

@ -2,7 +2,7 @@ from .models import Page
from django.http import HttpResponse from django.http import HttpResponse
from django.db import connections from django.db import connections
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.template import Template, Context
def search(request): def search(request):
with connections["default"].cursor() as cursor: with connections["default"].cursor() as cursor:
@ -15,4 +15,6 @@ def search(request):
def content(request, slug): def content(request, slug):
page = get_object_or_404(Page, slug=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")