博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DJANGO的HTTPRESPONSE流式输出
阅读量:7009 次
发布时间:2019-06-28

本文共 711 字,大约阅读时间需要 2 分钟。

在项目当中遇到的问题,网上有样例代码,但都不行,后来,发现在了1.5版本之后,新的STREAMHTTPRESPONSE对象,

搞定。

复制代码
from django.http import HttpResponsefrom django.http import StreamingHttpResponseimport timefrom django.views.decorators.http import condition@condition(etag_func=None)def stream_response(request):    #resp = HttpResponse( stream_response_generator(), mimetype='text/html')    resp = StreamingHttpResponse( stream_response_generator(), )    return respdef stream_response_generator():        yield "\n"    for x in range(1,15):        yield "
%s second putput
\n" % x yield " " * 1024 # Encourage browser to render incrementally time.sleep(1) yield "\n"def hello(request): return HttpResponse("hello world")
复制代码

转载地址:http://jyitl.baihongyu.com/

你可能感兴趣的文章
梳理下MySQL崩溃恢复过程
查看>>
红包金额均分实现
查看>>
Google校园招聘题 -- 程序员买房
查看>>
线程的属性(优先级、守护线程、未捕获异常处理器)
查看>>
oracle批量插入测试数据
查看>>
goahead-3.6.2-src 移植到linux
查看>>
Mysql数据库调优和性能优化的21条最佳实践
查看>>
iOS视频播放-MPMoviePlayerController
查看>>
mysql导入导出数据中文乱码解决方法小结
查看>>
使用Mob短信sdk遇到的问题,解决
查看>>
android-------- 强引用、软引用、弱引用、虚引用使用
查看>>
HTML标签marquee实现滚动效果
查看>>
html字符操作
查看>>
oracle函数
查看>>
百度贴吧爬虫1.0
查看>>
ant+jmeter接口批量执行测试用例
查看>>
Mongodb
查看>>
小规模低性能低流量网站设计原则
查看>>
POI之PPT-元素操纵
查看>>
python 将txt文件转换成excel
查看>>