python一个命令开启http服务器
1、python开启http服务器
python -m SimpleHTTPServer 8080
如果提示错误:
python.exe: No module named SimpleHTTPServer
则试一下命令:
python -m http.server
2、执行py脚本文件,开启cgi映射
python -m http.server --cgi 8000
py代码里添加
header = 'Content-Type: text/html\n'
print(header)
比如/cgi-bin/1.py文件代码:
header = 'Content-Type: text/html\n'
html = 'abc'
print(header)
print(html)
访问http://127.0.0.1:8000/cgi-bin/1.py
可以正常输出abc
Ps:
py代码文件默认目录在cgi-bin或者htbin
http.server官方文档 https://docs.python.org/3/library/http.server.html
如果觉得这文章还算用心,请劳驾点击右下角的推荐,这是对我们这些做开源分享的最大的肯定,谢谢。
作者:zqifa
出处:https://www.cnblogs.com/zqifa/
欢迎访问新博客地址:https://www.l1mn.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。