Aktuell habe ich nen http server welche die index.html Informationen via PAGE ausliest und auf dem Browser tatsächlich wieder ausgibt.
Code: Alles auswählen
import socketserver
from threading import Condition
from http import server
PORT_NUMBER = 8080 # Maybe set this to 9000.
PAGE = """\
<html>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1>Hallo</h1>
</body>
</html>
"""
class MyHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
elif self.path == '/index.html':
content = PAGE.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', len(content))
self.end_headers()
self.wfile.write(content)
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/css/style.css')
self.end_headers()
elif self.path == '/css/style.css':
self.send_response(200)
self.send_header('Content-Type', 'text/css')
self.end_headers()
else:
self.send_error(404)
self.end_headers()
class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
if __name__ == '__main__':
try:
address = ('', 8000)
server = StreamingServer(address, MyHandler)
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
Code: Alles auswählen
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/css/style.css')
self.end_headers()
elif self.path == '/css/style.css':
self.send_response(200)
self.send_header('Content-Type', 'text/css')
self.end_headers()
Jedoch kam der Inhalt der style.css leider nicht mit. Bedeutet die Datei ist leer, ob wohl die style.css mit Inhalt gefüllt ist.
Würde gerne hier das Bild hochladen, weiss aber nicht wie dies geht sorry
Was habe ich übersehen, könnte jemand sich dies anschauen?
Besten Dank
F