Search code examples
pythonhtmlpython-3.x

python3 http simple server doesn't host the index file in the right directory


let's say I have a directory which contains 6 other directories, (let's name them 01-06) in each of these directories there are two files, an index.html, and a style.css. now my preferred method of viewing html files is to cd into a directory and use python simple server (python3 -m http.server). At first it was fine then, but then, no matter which directory I ran the server in it would always display this screen. the page screen I get whenever I run the command (I use a dark mode extension which is why the background is dark) which is basically the html in 03 but without the styling. (yes, even if I run it inside 03 there would still be no styling)

I tried providing the --directory flag, and I tried running it elsewhere outside the main directory but the problem persists. I also tried to edit the contents of index.html of 03 but it doesn't change the page

edit: you might find these logs helpful

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [27/Aug/2024 22:22:14] "GET / HTTP/1.1" 304 -
127.0.0.1 - - [27/Aug/2024 22:22:28] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [27/Aug/2024 22:22:28] "GET /style.css HTTP/1.1" 200 -
127.0.0.1 - - [27/Aug/2024 22:22:28] code 404, message File not found
127.0.0.1 - - [27/Aug/2024 22:22:28] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [27/Aug/2024 22:24:12] "GET / HTTP/1.1" 304 -

there is a request between the initialization of the server and 22:22:14 in a private window where I got the expected results. the 22:22:14 request was a refresh in that page. all of the 22:22:28 requests are made in a new private window where I got the expected results(I have no idea what favicon.ico is). the 22:24:12 request was made in a regular window where I got the wrong results


Solution

  • I have no idea what fixed, but all I did was delete some extension (none of which should affect the problem) and restarted

    edit: problem happened again clearing cache fixed it