Render content
This commit is contained in:
parent
d5988001a3
commit
4c25b7cd91
4 changed files with 13 additions and 2 deletions
|
@ -2,4 +2,6 @@
|
||||||
title: Test
|
title: Test
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# Heading
|
||||||
|
|
||||||
My content
|
My content
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
django
|
django
|
||||||
git+https://github.com/andrewgodwin/yamdl
|
git+https://github.com/andrewgodwin/yamdl
|
||||||
gunicorn
|
gunicorn
|
||||||
|
markdown
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue