加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – mod_wsgi产生输出缓冲区而不是返回

发布时间:2020-12-20 12:35:46 所属栏目:Python 来源:网络整理
导读:现在我有一个mod_wsgi脚本,结构如下. def application(environ,start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type','text/plain'),('Content-Length',str(len(output)))] start_response(status,response_hea
现在我有一个mod_wsgi脚本,结构如下.

def application(environ,start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type','text/plain'),('Content-Length',str(len(output)))]
    start_response(status,response_headers)

    return [output]

我想知道是否有人知道一种方法来改变它以收益率而不是返回操作,这样我就可以在生成页面时发送它,而不仅仅是一旦完成,所以页面加载对于用户来说可以更快.

但是,每当我将输出交换为列表并在application()中生成它时,它都会抛出一个错误:

TypeError: sequence of string values expected,value of type list found

解决方法

def application(environ,response_headers)

    yield output

“However,whenever I swap the output for a list and yield it in the application(),it throws an error:”

好吧,不要列出清单.产生每个元素:

for part in mylist:
    yield part

或者如果列表是整个内容,只需:

return mylist

因为列表已经是迭代器并且可以单独生成.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读