web hello word

来源:互联网 发布:淘宝如何自动发货 编辑:程序博客网 时间:2024/05/18 20:11

原文:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386832689740b04430a98f614b6da89da2157ea3efe2000



hello.py


# coding:utf-8
def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return '<h1>Hello, web!</h1>'


server.py

# coding:utf-8


# 从wsgiref模块导入:
from wsgiref.simple_server import make_server
# 导入我们自己编写的application函数:
from hello import application


# 创建一个服务器,IP地址为空,端口是8000,处理函数是application:
httpd = make_server('', 8000, application)
print "Serving HTTP on port 8000..."
# 开始监听HTTP请求:
httpd.serve_forever()

终端中进入server.py所在的目录,执行 python server.py

wooddeMacBook-Pro:www wood$ python server.py 

Serving HTTP on port 8000...

127.0.0.1 - - [20/May/2015 09:48:57] "GET / HTTP/1.1" 200 20

127.0.0.1 - - [20/May/2015 09:48:57] "GET /favicon.ico HTTP/1.1" 200 20

这样8000端口就跑起来了,我们在web浏览器中输入 localhost:8000

页面显示:

hello word!

第一个web hello 运行啦





0 0