WSGI

一.WSGI

WSGI:Web Server Gateway Interface,web服务接口

二.WSGI接口定义

WSGI接口定义非常简单,它只要求Web开发者实现一个函数,就可以响应HTTP请求

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

  

三.简单示例:

from wsgiref.simple_server import make_server

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

httpd = make_server('', 5900, application)
httpd.serve_forever()

  

更多时候我们会使用其他web框架,比如flask

posted @ 2019-01-16 09:05  rorshach  阅读(167)  评论(0编辑  收藏  举报