从本地运行的http服务器访问本地文件

277*_*han 5 python web

我想使用 url 访问本地计算机中的文件。例如“file:///usr/local/home/thapaliya/constants.py”。实现这一目标的最佳方法是什么?

Mik*_*maa 2

使用简单的 HTTP 服务器:

  python -m http.server 8000
Run Code Online (Sandbox Code Playgroud)

或者对于 Python 2:

  python -m SimpleHTTPServer 8000
Run Code Online (Sandbox Code Playgroud)

https://docs.python.org/3/library/http.server.html