I'm stumped. The below code will return the index.html as well as the css asked for, but when the index.html is requested by Firefox, it won't render the page with the css applied. I have the same result in Konqueror (which in Chrome based)
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
if (self.path.endswith("/")):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
with open('index.html', 'r') as file:
template = file.read()
self.wfile.write(bytes(eval_template(template, env).encode("utf-16")))
elif (self.path.endswith(".css")):
with open(os.path.join('.', self.path[1:]), 'rb') as file:
response = file.read()
self.send_response(200)
self.send_header("Content-type", "text/css")
self.end_headers()
self.wfile.write(response)
The css is referenced in the index.html in this manner:
<link rel="stylesheet" type="text/css" href="style.css" />
When I look in the developer console, I can verify that the request for style.css file went without issue (200 OK).
When I open the file with Firefox as a file, it sees the css as well in the same directory and renders the file with the css as intended, so I'm inclined to think my code above is missing something.
Thanks for any help with this.
href="style.css?xyz". If that resolves the issue it means the css file was stuck in the cache. For a permanent solution, affix something to it dynamically, such as the time, while in development.self.wfile.write()