45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import os
|
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "whispermaphone.settings"
|
|
|
|
import django
|
|
from django.template.loader import render_to_string
|
|
from django.utils import timezone
|
|
|
|
django.setup()
|
|
from main.models import Thought
|
|
|
|
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
|
|
|
from decouple import config
|
|
|
|
app = JetforceApplication()
|
|
|
|
|
|
@app.route("", strict_trailing_slash=False)
|
|
def index(request):
|
|
thoughts = Thought.objects.order_by("-posted")
|
|
|
|
rendered_text = render_to_string("whispermaphone/index.gmi", {
|
|
"thoughts": thoughts,
|
|
})
|
|
|
|
return Response(Status.SUCCESS, "text/gemini", rendered_text)
|
|
|
|
|
|
@app.route("/about", strict_trailing_slash=False)
|
|
def about(request):
|
|
return Response(Status.SUCCESS, "text/gemini", render_to_string("whispermaphone/about.gmi"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
server = GeminiServer(
|
|
app=app,
|
|
host="0.0.0.0",
|
|
hostname="localhost",
|
|
certfile=config("CERTFILE", default=None),
|
|
keyfile=config("KEYFILE", default=None),
|
|
port=1973
|
|
)
|
|
server.run()
|