• 技术文章 >Python技术 >Python高级

    python WSGI规范是什么

    小妮浅浅小妮浅浅2021-07-23 09:33:38原创4200

    1、WSGI协议规定,Application端需要成为可调用目标(函数、类别等)。

    def simple_app(environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type', 'text/plain')]
        start_response(status, response_headers)
        return ['Hello world!\n']

    2、Server端也使用函数来实现。

    import os
     
     
    def wsgi_server(application):
        environ = dict(os.environ.items())
     
        def start_response(status, response_headers):
            print(f'status: {status}')
            print(f'response_headers: {response_headers}')
     
        result = application(environ, start_response)
        for data in result:
            print(f'response_body: {data}')

    以上就是python WSGI规范的介绍,希望对大家有所帮助。更多编程基础知识学习:python学习网

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python wsgi
    品易云
    上一篇:python如何进行内存管理 下一篇:Python中tail -f如何实现

    相关文章推荐

    • python中and关键字是什么• python not关键字的使用• python如何输入• python如何下载模块• python函数的理解及定义• python调用函数的注意点• python中函数的作用探究• python try-except捕获异常的方法• python中try-except-finally语句的使用• python raise语句的两种用法• python类如何实例化对象• python密码生成器的使用• python如何使用send唤醒

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网