码迷,mamicode.com
首页 > 编程语言 > 详细

python一个命令开启http服务器

时间:2017-12-14 21:09:37      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:htm   org   print   content   serve   默认   post   mod   tps   

 

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服务器

标签:htm   org   print   content   serve   默认   post   mod   tps   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!