From: Christian Heller Date: Sat, 16 Mar 2024 21:44:07 +0000 (+0100) Subject: Add Jinja2 templating, and requirements.txt infrastructure. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/error?a=commitdiff_plain;h=802fad1325647a1e842dcfbdcaff3a391ac3b04c;p=plomtask Add Jinja2 templating, and requirements.txt infrastructure. --- diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cd1737d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Jinja2==3.1.3 diff --git a/scripts/setup_dev_environment.sh b/scripts/setup_dev_environment.sh index 8ea3a44..32848d9 100755 --- a/scripts/setup_dev_environment.sh +++ b/scripts/setup_dev_environment.sh @@ -3,7 +3,11 @@ set -e if [ ! -d '.git' ]; then echo "Cannot find .git/, please run me from your cloned repo's top directory!" -elif [ ! -f '.git/hooks/pre-commit' ]; then +fi + +pip install -r requirements.txt + +if [ ! -f '.git/hooks/pre-commit' ]; then echo 'Linking pre-commit hook.' cd .git/hooks/ ln -s ../../scripts/pre-commit diff --git a/task.py b/task.py index a1510b0..2a6c699 100755 --- 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 = '

hi there!

' + 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() diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..508281e --- /dev/null +++ b/templates/base.html @@ -0,0 +1,8 @@ + + + + +{% block content %} +{% endblock %} + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..72d81d4 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,5 @@ +{% extends 'base.html' %} + +{% block content %} +Hi there! +{% endblock %}