framework.py
import time
def index():
status = "200 OK"
response_headers = [("Server", "PWS/1.1")]
with open("website/index.html", "r") as file:
file_data = file.read()
data = time.ctime()
response_body = file_data.replace("{%content%}",data)
return status, response_headers, response_body
def not_found():
status = "404 Not Found"
response_headers = [("Server", "PWS/1.1")]
data = "not found"
return status, response_headers, data
route_list = [("/index.html", index)]
def handler_request(env):
request_path = env["request_path"]
print(request_path)
for path, func in route_list:
if path == request_path:
result = func()
return result
else:
result = not_found()
return result