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

posted on   zqifa  阅读(21853)  评论(0)    收藏  举报

编辑推荐:
· 记一次 .NET某云HIS系统 CPU爆高分析
· 如果单表数据量大,只能考虑分库分表吗?
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
阅读排行:
· 如果单表数据量大,只能考虑分库分表吗?
· 一款让 Everything 更加如虎添翼的 .NET 开源辅助工具!
· (原创)[开源][.Net Framework 4.5] SimpleMVVM(极简MVVM框架)更
· 冲压车间软件实施
· 干货分享!MCP 实现原理,小白也能看懂

导航

< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10
点击右上角即可分享
微信分享提示