Local host server bug
I started a local host server using python3 -m http.server Wanted to view the listing of the directory "Web" in my browser (Firefox and Edge tested). Instead of the directory, it opens "index.html" all the time. The problem persists until I change the name of this file to others. Took me 2 days to diagnose the problem (even took the time to install Ubuntu and tested it). Sorry if this is a known bug.
Hi Bach,
I started a local host server using python3 -m http.server Instead of the directory, it opens "index.html" all the time.
It's not even a bug, it's a convention: https://en.wikipedia.org/wiki/Webserver_directory_index In other words there's two cases: - Either the URL points to a file, the file is served, no surprises. - Either the URL points to a directory, and here there's a choice : Either display a "directory listing" or pick a file and display this file. I don't really know about a formal specification around "index.html", I think it's just a consensus that arose by itself, "it has always been like this". It's also documented in SimpleHttpRequestHandler:
If the request was mapped to a directory, the directory is checked for a file named `index.html` or `index.htm` (in that order). If found, the file’s contents are returned; otherwise a directory listing is generated by calling the `list_directory()` method.
_ https://docs.python.org/3/library/http.server.html#http.server.SimpleHTTPReq... If you think it should be documented also elsewhere, don't hesitate to propose it (like: where you searched?).
Took me 2 days to diagnose the problem
I hope you learned a lot during this "trip" :) Bests, -- Julien Palard https://mdk.fr
Thank you very much! I did not expect to receive a reply this early, and I am really grateful for your help. Anyway, best wishes to you and your work! On Mon, Jul 8, 2019, 23:00 Julien Palard <julien@palard.fr> wrote:
Hi Bach,
I started a local host server using python3 -m http.server Instead of the directory, it opens "index.html" all the time.
It's not even a bug, it's a convention: https://en.wikipedia.org/wiki/Webserver_directory_index
In other words there's two cases: - Either the URL points to a file, the file is served, no surprises. - Either the URL points to a directory, and here there's a choice : Either display a "directory listing" or pick a file and display this file.
I don't really know about a formal specification around "index.html", I think it's just a consensus that arose by itself, "it has always been like this".
It's also documented in SimpleHttpRequestHandler:
If the request was mapped to a directory, the directory is checked for a file named `index.html` or `index.htm` (in that order). If found, the file’s contents are returned; otherwise a directory listing is generated by calling the `list_directory()` method.
_ https://docs.python.org/3/library/http.server.html#http.server.SimpleHTTPReq...
If you think it should be documented also elsewhere, don't hesitate to propose it (like: where you searched?).
Took me 2 days to diagnose the problem
I hope you learned a lot during this "trip" :)
Bests, -- Julien Palard https://mdk.fr
participants (3)
-
Bach
-
Julien Palard
-
Ngoc Bach Nguyen