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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值