django - how to use StreamingHttpResponse in render_to_response -
i tried use streaminghttpresponse in render_to_response,but failed. codes below:
def index(request): def test(): yield "nihaoma" import time time.sleep(5) yield "shidene" yield "haodene" #return streaminghttpresponse(test()) return render_to_response("result.html",{'output':streaminghttpresponse(test())})
i can want return streaminghttpresponse(test()),however,i want let string print browser can more goodlooking,so want print in result.html templete file , tried use render_to_response("result.html",{'output':streaminghttpresponse(test())}),but can not print strings in def test(),it print <django.http.response.streaminghttpresponse object @ 0x7f71dbfa05f8>
browser.
my result.html file content is:
{% extends "base.html" %} {% block extrastyle %} <style> #myoutput{ position:fixed; top: 30%; left: 50%; width:45%; height:60%; margin-top: 0px; margin-left: -22%; border: 15px solid transparent; background-color: transparent; color:#ffc080; font-size:15px; font-weight:600; font-family:文泉驿等宽正黑; overflow:auto; } </style> {% endblock %} {% block content %} <div id="myoutput"> {{ output|linebreaksbr }} </div> {% endblock %}
can me? [i worked on django 1.10.3] thx.
Comments
Post a Comment