WSGI.应用接口

WSGI应用接口被实现为可调用的对象:一个函数,方法,类或者一个带有__call__方法的实例。这个可调用对象

1. 必须接受两个位置参数:

一个包含类似于CGI变量的字典;

一个回调函数,这个回调函数将被应用用来发送HTTP状态码/消息和HTTP头给服务器。

2. 必须向服务器返回以可迭代对象包含的字符串的应答体。


程序骨架:

# This is our application object . it could hava any name, except when using mod_wsgi where it must be "application"

def application( # It accepts two arguments: environ points to a dictionary containing CGI like environment variables which is filled by the server for each received request #from the client

environ,

# start_response is a callback function supplied by the server which will be used to send the HTTP status and headers to the server

start_response)

    # build the response body possibility using the environ dictionary

    response_body = 'The request method was %s' environ['REQUEST_METHOD']

    # HTTP response code and message

    status = '200 OK'

    # These are HTTP headers expected by the client.

    # They must be wrapped as a list of tupled pairs:

    # [(Header name, Header value)].

    response_headers = [('Content-Type', 'txt/plain'), ('Content-Length',str(len(response_body)))]

    # send them to the server using the supplied function

    start_response(status, response_headers)

    # return the response body, Notice it is wrapped in a list although it could be any iterable

    return [reponse_body]


由于缺少服务器实例化步骤,这个代码不能运行。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
mod_wsgi.so是一个Apache模块,用于在Apache服务器上运行使用Python编写的Web应用程序。它是将Python应用程序和Apache服务器结合在一起的桥梁。 mod_wsgi.so的主要功能是将Python应用程序与Apache服务器之间进行通信。它以动态共享对象(.so)的形式提供,可以通过在Apache的配置文件中加载该模块来启用。 使用mod_wsgi.so可以将Python应用程序与Apache服务器无缝地集成在一起。它提供了一个接口,使得Python应用程序可以通过Apache服务器来处理HTTP请求和响应。这样,Python应用程序可以像静态HTML文件一样被Apache服务器直接访问。 加载mod_wsgi.so后,Apache服务器会创建一个守护进程,该进程用于处理Python应用程序的请求。这个守护进程会监听指定的端口,并将接收到的HTTP请求转发给Python应用程序进行处理。然后,将Python应用程序的响应返回给客户端。 mod_wsgi.so还提供了一些配置选项,使得可以根据需求来调整Python应用程序和Apache服务器之间的通信方式。例如,可以配置应用程序运行的Python解释器路径,设置线程和进程的数目,以及调整日志记录等功能。 总之,mod_wsgi.so是一个重要的工具,可以使得使用Python编写的Web应用程序能够在Apache服务器上运行,并且与服务器进行无缝的集成。它极大地简化了部署和管理Python应用程序的过程,提高了应用程序的性能和稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值