I’m trying my first attempt to write an http server. I am baffled by do_GET and cannot find any worth while examples of how to use it. The documentation, to me, is severely lacking. I think my main problem is I don’t understand how css and js files are served out or links are handled. I found a simple example which I copied and while the main page is displayed, neither the css nor js files are included. Unfortunately, the example is too simple and does not show how do_GET really works but it is the only one I could find.
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() fh=open('jindex.html','rb') string=fh.read() self.wfile.write(string)
I’m guessing that when a get request comes in for style.css that this is just reloading jindex.html. How do I get the requested filename so I can server it out? It also may be a directory issue as the directory containing the files is under the current directory as ‘html’. I do “os.chdir(’./html’)” and it finds the file but gives me an os.chdir error no such file or directory exists. If I leave that out it cannot find the html file.