WSGI

一.WSGI

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

二.WSGI接口定义

WSGI接口定义很是简单,它只要求Web开发者实现一个函数,就能够响应HTTP请求web

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框架,好比flaskflask

相关文章
相关标签/搜索