WhisperMaPhone/jetforce_app.py

45 lines
1.0 KiB
Python
Raw Normal View History

2021-06-11 17:31:07 +00:00
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 thoughts.models import Thought
2021-06-11 17:31:07 +00:00
from jetforce import GeminiServer, JetforceApplication, Response, Status
2021-06-25 07:22:48 +00:00
from decouple import config
2021-06-11 17:31:07 +00:00
app = JetforceApplication()
2021-06-11 17:31:07 +00:00
@app.route("", strict_trailing_slash=False)
def index(request):
thoughts = Thought.objects.order_by("-posted")
rendered_text = render_to_string("thoughts/index.gmi", {
2021-06-11 17:31:07 +00:00
"thoughts": thoughts,
})
return Response(Status.SUCCESS, "text/gemini", rendered_text)
2021-06-11 17:31:07 +00:00
@app.route("/about", strict_trailing_slash=False)
def about(request):
2022-05-07 21:11:11 +00:00
return Response(Status.SUCCESS, "text/gemini", render_to_string("thoughts/about.gmi"))
2021-06-11 17:31:07 +00:00
if __name__ == "__main__":
server = GeminiServer(
app=app,
2021-06-25 07:22:48 +00:00
host="0.0.0.0",
hostname="localhost",
2021-06-25 07:22:48 +00:00
certfile=config("CERTFILE", default=None),
keyfile=config("KEYFILE", default=None),
port=1973
2021-06-11 17:31:07 +00:00
)
server.run()