美文网首页
wsgi简介

wsgi简介

作者: 飘涯 | 来源:发表于2019-01-29 20:30 被阅读5次

wsgi是什么?

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

  • 创建一个读取时间的py文件
    传入两个参数,一个env,一个报头,根据解析出来的env,作出不同的处理。
#-*- conding:utf-8 -*-
import time
def applitation(env,start_response):
    # env.get("Method")
    # env.get("Path_Info")
    #
    states = "200 OK"
    headers = {
        ("Content-Type","text/plain")
    }
    start_response(states,headers)
    return time.ctime()
  • 编写回调函数,回调函数一般没有返回值,用self方法直接实现更新
    def start_response(self,status,headers):
        '''
         states = "200 OK"
    headers = {
        ("Content-Type","text/plain")
    }
        '''
        response_headers = "HTTP/1.1 " + status +"\r\n"
        for head in headers:
            response_headers += "%s: %s\r\n"%head
        self.response_headers =response_headers

作用

可以方便功能扩展

  • sys进行默认文件夹填充
sys.path.insert(1,WSGI_PYTHON_DIR)
  • 自调用
def __call__(self)

服务器和框架示意图

image.png

相关文章

  • python wsgi+Odoo 的启动

    参考:WSGI初探Odoo web 机制浅析python的 WSGI 简介python wsgi 简介 wsgi的...

  • WSGI 简介

    WSGI 背景 python Web 开发中,服务端程序可以分为两个部分: 服务器程序 应用程序 服务器程序 负责...

  • WSGI简介

    背景 Web开发中,服务器端的程序分为两个部分,一个是服务器程序,负责接收客户端请求和整理客户端请求,一个是应用程...

  • WSGI简介

    结合案例Python部署 & 示例代码wsgi-demo All in One WSGI WSGI = Pytho...

  • wsgi简介

    wsgi是什么? WSGI:Web Server Gateway Interface。WSGI接口定义非常简单,它...

  • WSGI--python web服务器接口

    WSGI简介 WSGI:Web Server Gateway Interface是python web服务器网关接...

  • OpenStack Restful API基础简介

    Restful API开发框架简介 WSGI + Paste + Paste_Deploy + Routes + ...

  • WSGI服务器简介

    HTTP协议 http协议是:是基于TCP/IP协议超文本传输协议,它是一个短连接。超文本是指由HTML标签语言编...

  • 深入理解nova api服务

    一、wsgi简介 在构建 Web 应用时,通常会有 Web Server 和 Application Server...

  • wsgi&uwsgi

    WSGI协议 WSGI, aka Web Server Gateway Interface, WSGI 不是服务器...

网友评论

      本文标题:wsgi简介

      本文链接:https://www.haomeiwen.com/subject/cqlfsqtx.html