4

巧用 python 随时随地开启 http 服务器

 2 years ago
source link: https://blog.diqigan.cn/posts/http-server-in-python.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

近来发现 Python 中内置了一个小巧的 HTTP 服务器,轻微使用的话及其方便。特撰此文,作为记录.

  1. 进入到自己想要开启 HTTP 服务器的目录;

  2. 输入对应命令即可:

    # python3
    python -m http.server
    # python3 指定端口
    python -m http.server 8000
    # python2 
    python -m SimpleHTTPServer

    此时,HTTP 服务器就启动在本机的 8000 端口了.

  1. 预览前端项目:

    如果当前目录下存在 HTML 文件,那么这个 HTTP 服务器可以直接用来预览前端项目.

  2. 临时文件传输:

    如果当前目录下不存在 index.html, 就会显示当前目录下的文件列表。你可以在开启 HTTP 服务器后把自己的 ip 以及端口告诉朋友,朋友就可以直接通过网页下载你对应目录下的文件啦.

参考文献:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK