首页 > 编程语言 > 详细

Python -- Web -- WSGI

时间:2015-10-26 18:29:38      阅读:259      评论:0      收藏:0      [点我收藏+]

WSGI:Web Server Gateway Interface

  只要求Web开发者实现一个函数,就可以响应HTTP请求。

 

# hello.py

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

 

# server.py
from wsgiref.simple_server import make_server

from hello import application

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

运行server.py,浏览器中输入IP:8000即可访问

技术分享

 

Python -- Web -- WSGI

原文:http://www.cnblogs.com/roronoa-sqd/p/4911693.html

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