home · contact · privacy
Add Jinja2 templating, and requirements.txt infrastructure.
[plomtask] / task.py
diff --git a/task.py b/task.py
index a1510b0a202571796a5da96262fc115fb3e85a84..2a6c699f99cb956192a33727a69cb7f808cd8ff2 100755 (executable)
--- a/task.py
+++ b/task.py
@@ -4,8 +4,10 @@ plom's task manager
 """
 from http.server import BaseHTTPRequestHandler
 from http.server import HTTPServer
+from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
 
 HTTP_PORT = 8082
+TEMPLATES_DIR = 'templates'
 
 
 class HandledException(Exception):
@@ -19,13 +21,14 @@ class TaskHandler(BaseHTTPRequestHandler):
         """Handle any GET request."""
         self.send_response(200)
         self.end_headers()
-        html = '<html><body><p>hi there!</p></body></html>'
+        html = self.server.jinja.get_template('index.html').render()
         self.wfile.write(bytes(html, 'utf-8'))
 
 
 def main():
     """Main loop."""
     server = HTTPServer(('localhost', HTTP_PORT), TaskHandler)
+    server.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR))
     print(f'running at port {HTTP_PORT}')
     try:
         server.serve_forever()