Reputation: 41
I have a problem when I want to host an HTML file using python on the web server.
I go to cmd and type this in:
python -m http.server
The command works but when I open the domain name I get a list of HTML pages, which I can click and they open. How can I make it so that when I open the domain in chrome it immediately shows me the main.html?
Thank you
Upvotes: 1
Views: 4489
Reputation: 1645
You can add additional options:
python -m http.server --directory C:/ESD/ --bind 127.0.0.1
--directory
will tell python in which folder to look for html files, here i specified the path C:/ESD/
--bind
will tell python on which ip the server should run at
If you want to directly open the file instead of the directory listing all html files, you have to rename your main.html
to index.html
Upvotes: 1
Reputation: 36510
it works but when I open it up in chrome it shows me lists of my html files and when I click on one it goes to it.
This is expected behavior.
how can I do it so that when I open it in chrome it immediately shows me the main.html?
Rename main.html
to index.html
. As docs says standard procedure to handle GET
request is
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. This method uses os.listdir() to scan the directory, and returns a 404 error response if the listdir() fails.
Upvotes: 0