原问题: Streaming data with Python and Flask 我需要把这段代码做下改动,如下所示,但这段代码一直报错:raise RuntimeError: working outside of request context 初看是因为 request 变量没有传到 ggg1() 函数里面去,我调试了好久也没找出原因。。。 哪位同学能看懂啥原因的,解释下怎么改,以及为啥? 先谢过了~
代码如下:
@app.route('/username', methods=['GET', 'POST'])
def index():
req =request
print req
print "111------------" + req.method + "\n"
def ggg1(req):
print req # the req not my pass into the req....
print "444------------" + req.method + "\n"
if req.method == 'POST':
if request.form['username']:
urlList = request.form['username'].splitlines()
i = 0
for url in urlList():
i += 1
resultStr = chkListPageContent(url, getUrlContent(url), "script")
print i, resultStr
yield i, resultStr
print req
print "222------------" + req.method + "\n"
return Response(stream_template('index.html', data=ggg1(req)))
走同样的路,发现不同的人生