From 5a3f55920d816715fab993fbf1a8742add3adf8f Mon Sep 17 00:00:00 2001 From: ocueye2 Date: Tue, 20 Aug 2024 16:58:43 +0000 Subject: [PATCH] added 404 support --- ezweb.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++--- html/404.html | 3 ++ 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 html/404.html diff --git a/ezweb.py b/ezweb.py index e52d54f..a09d688 100644 --- a/ezweb.py +++ b/ezweb.py @@ -101,14 +101,93 @@ class MyHandler(SimpleHTTPRequestHandler): # send out html self.wfile.write(content.encode()) else: - # 404 page - # todo: add custom 404 pages + selfpath = "404" + + # html loading + try: + h = open(f"{path}/html/{selfpath}.html") + ch = h.read() + except: + ch = "

404 not found

ezweb

" + + try: + c = open(f"{path}/html/nav.html") + nav = c.read() + except: + nav="" + print("no all.css found, skiping") + + #css loading + + try: + c = open(f"{path}/css/{selfpath}.css") + cc = c.read() + except: + cc = "" + try: + c = open(f"{path}/css/all.css") + ccss = c.read() + except: + print("no all.css found, skiping") + + #JS LOADING + try: + c = open(f"{path}/script/{selfpath}.js") + js = c.read() + except: + js="" + print("no all.css found, skiping") + + try: + c = open(f"{path}/script/all.js") + ajs = c.read() + except: + ajs="" + print("no all.css found, skiping") + + + + self.send_header('Content-type', 'text/html') + self.end_headers() + + # Merge all the files together procedrealy + # todo: make compiler verson of this + content = f""" + + + + + + {nav} + {ch} + + + + """ print(paths.replace("/","")) - # If the - # path is not /test, return a 404 Not Found response + + self.send_response(404) self.end_headers() - self.wfile.write(b"404 Not Found") + self.send_header('Content-type', 'text/html') + self.end_headers() + + + + + content = "" + self.wfile.write(content.encode()) + print(content) # Set the server address and port server_address = ('', port) diff --git a/html/404.html b/html/404.html new file mode 100644 index 0000000..194785a --- /dev/null +++ b/html/404.html @@ -0,0 +1,3 @@ + +

uh oh

+

This is 404.html for when the page could not be found

\ No newline at end of file