-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
49 lines (36 loc) · 1.1 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# gunicorn
def render_template(template_name="index.html", context={}):
html_str = ""
with open(template_name, "r") as f:
html_str = f.read()
html_str = html_str.format(**context)
return html_str
def home(environ):
return render_template(
template_name="index.html",
context={}
)
def contact_us(environ):
return render_template(
template_name="contact.html",
context={}
)
def app(environ, start_response):
path = environ.get("PATH_INFO")
if path.endswith("/"):
path = path[:-1]
if path == "":
# data = render_template(template_name="index.html", context={"path": path})
data = home(environ)
elif path == "/contact":
data = contact_us(environ)
else:
data = render_template(template_name="404.html", context={"path": path})
data = data.encode("utf-8")
start_response(
f"200 OK", [
("Content-Type", "text/html"),
("Content-Length", str(len(data)))
]
)
return iter([data])