1
Fork 0
yamdl-playground/yamdl_playground/core/views.py
2024-03-31 14:20:03 +01:00

23 lines
775 B
Python

from .models import Page
from django.http import HttpResponse
from django.db import connections
from django.shortcuts import get_object_or_404, render
from django.template import Template, Context
def search(request):
with connections["default"].cursor() as cursor:
cursor.execute("SELECT rowid FROM search_index WHERE search_index = %s;", ["content"])
row = cursor.fetchone()
pages = Page.objects.filter(id__in=row)
return HttpResponse(str(pages), content_type="text/plain")
def content(request, slug):
page = get_object_or_404(Page, slug=slug)
template = Template(page.content)
return render(request, "content.html", {
"page": page,
"content": template.render(Context({"request": request, "page": page}))
})