1
Fork 0

Render content

This commit is contained in:
Jake Howard 2023-12-12 18:11:44 +00:00
parent d5988001a3
commit 4c25b7cd91
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 13 additions and 2 deletions

View file

@ -2,4 +2,6 @@
title: Test title: Test
--- ---
# Heading
My content My content

View file

@ -1,3 +1,4 @@
django django
git+https://github.com/andrewgodwin/yamdl git+https://github.com/andrewgodwin/yamdl
gunicorn gunicorn
markdown

View file

@ -1,10 +1,17 @@
from .models import Page 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
import markdown
def test(request): def search(request):
with connections["default"].cursor() as cursor: with connections["default"].cursor() as cursor:
cursor.execute("SELECT rowid FROM search_index WHERE search_index = %s;", ["content"]) cursor.execute("SELECT rowid FROM search_index WHERE search_index = %s;", ["content"])
row = cursor.fetchone() row = cursor.fetchone()
pages = Page.objects.filter(id__in=row) pages = Page.objects.filter(id__in=row)
return HttpResponse(str(pages), content_type="text/plain") return HttpResponse(str(pages), content_type="text/plain")
def content(request, id):
page = get_object_or_404(Page, id=id)
return HttpResponse(markdown.markdown(page.content), content_type="text/html")

View file

@ -18,5 +18,6 @@ from django.urls import path
from .core import views from .core import views
urlpatterns = [ urlpatterns = [
path("test/", views.test) path("search/", views.search),
path("content/<int:id>/", views.content)
] ]