简体   繁体   中英

Python http.server: how open indexOtherName.html?

I am using a python 3 web server. I have four webpages that I'm developing and need to view in the browser at different times, say index1.html, index2.html, index3.html, index4.html. These files have dependencies on stylesheets and scripts in subfolders.

In my CLI I use: python -m http.server to start the server

Is there some other command whereby localhost:8000 will display a specific file rather than the default index.html?

Thanks

Unfortunately not.

If you look at the http.server source code at https://github.com/python/cpython/blob/3.7/Lib/http/server.py#L687-L693 , you will see it only searches the current directory for index.html or index.htm files and if not found, it returns the directory listing.

for index in "index.html", "index.htm":
    index = os.path.join(path, index)
    if os.path.exists(index):
        path = index
        break
else:
    return self.list_directory(path)

Furthermore, there is no commandline argument to serve only a single file. See https://github.com/python/cpython/blob/3.7/Lib/http/server.py#L1240-L1262

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM