首页 > 编程语言 > 详细

python一个命令开启http服务器

时间:2017-12-14 20:23:18      阅读:234      评论:0      收藏:0      [点我收藏+]

 

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

python一个命令开启http服务器

原文:http://www.cnblogs.com/gjack/p/8039545.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!