Commit 2dfc24fa authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers 🍪

initial commit

parents
__pycache__/
#! /usr/bin/env python3
TEMPLATE_DIR = "templates"
from jinja2 import Environment, PackageLoader, select_autoescape
env = Environment(
loader=PackageLoader('test', TEMPLATE_DIR),
autoescape=select_autoescape(['html', 'xml'])
)
def render(name):
template = env.get_template(name)
return template.render()
# Static jinja replacement
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "_base.html" %}
{% block content %}test{% endblock %}
#! /usr/bin/env python3
##
# Dynamic server mode
#
# This is useful for development because you can see the changes made in real time
##
import main
from http.server import BaseHTTPRequestHandler
import socketserver
PORT = 8082
class TemplateHTTPServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
data = main.render('index.html')
self.wfile.write(data.encode())
Handler = TemplateHTTPServer
httpd = socketserver.TCPServer( ("", PORT), Handler)
httpd.serve_forever()
httpd.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment