加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python一个命令开启http服务器

发布时间:2020-12-20 10:06:00 所属栏目:Python 来源:网络整理
导读: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代码里添加 heade

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/htmln'
print(header)

比如/cgi-bin/1.py文件代码:

header = 'Content-Type: text/htmln'
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读