Zwischenstand erster Praktikumstag: Aufgaben 1-3 funktionieren, Aufgabe 4 ist noch zu implementieren
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import http.server
|
||||
import urllib.parse
|
||||
|
||||
class MyOwnHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
print("Geparsed wurde: ", parsed)
|
||||
|
||||
myOwnPath = parsed.path
|
||||
print("Variable myOwnath ist :", myOwnPath)
|
||||
|
||||
nameOfMyOwnPath = myOwnPath[1:4].upper() #schneidet "/" am Anfang ab und verwandelt "yang" zu "YANG" bzw "ying" zu "YING, damit Titel des HTML-Files später "YANG_File" bzw "YING_File" ist
|
||||
MyOwnQuery = parsed.query
|
||||
|
||||
msg_to_return = f"<html><head><title>{nameOfMyOwnPath}_File</title></head>"
|
||||
|
||||
if myOwnPath == "/Ying":
|
||||
msg_to_return += "<body><p>This is the Ying-page.</p>"
|
||||
msg_to_return += f"<p>You accessed path: {myOwnPath}</p>"
|
||||
msg_to_return += '<a href="Yang">Go to Yang-Page</a>'
|
||||
msg_to_return += "</body></html>"
|
||||
|
||||
if myOwnPath == "/Yang":
|
||||
msg_to_return += "<body><p>This is the Yang-page.</p>"
|
||||
msg_to_return += f"<p>You accessed path: {myOwnPath}</p>"
|
||||
msg_to_return += '<a href="Ying">Go to Ying-Page</a>'
|
||||
msg_to_return += "</body></html>"
|
||||
|
||||
self.wfile.write(msg_to_return.encode("utf-8"))
|
||||
|
||||
|
||||
# self.wfile.write(f"<html><head><title>{nameOfMyOwnPath}_File</title></head>".encode('utf-8'))
|
||||
#
|
||||
# if myOwnPath == "/Ying":
|
||||
# self.wfile.write("<body><p>This is the Ying-page.</p>".encode('utf-8'))
|
||||
# self.wfile.write(f"<p>You accessed path: {myOwnPath}</p>".encode('utf-8'))
|
||||
# self.wfile.write('<a href="YANG_File">Go to Yang-Page</a>'.encode('utf-8'))
|
||||
# self.wfile.write("</body></html>".encode('utf-8'))
|
||||
# self.wfile.close()
|
||||
#
|
||||
# if myOwnPath == "/Yang":
|
||||
# self.wfile.write("<body><p>Sie sind auf der Yang-Seite.</p>".encode('utf-8'))
|
||||
# self.wfile.write(f"<p>Eigener Pfad: {myOwnPath}</p>".encode('utf-8'))
|
||||
# self.wfile.write('<a href="YING_File">Gehe zur Ying-Seite</a>'.encode('utf-8'))
|
||||
# self.wfile.write("</body></html>".encode('utf-8'))
|
||||
# self.wfile.close()
|
||||
|
||||
|
||||
port = 22233
|
||||
handler = MyOwnHandler
|
||||
address = ('', port)
|
||||
|
||||
myserver = http.server.HTTPServer(address, handler)
|
||||
myserver.serve_forever()
|
||||
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Yang_File</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Sie sind auf der Yang-Page :P
|
||||
<a href="http://localhost:22233/ying"> Gehe zur Ying-Seite</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Ying_File</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Sie sind auf der Ying-Page :-)
|
||||
<a href="http://localhost:22233/yang"> Gehe zu Yang-Page</a>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user