从问题中:
Streaming data with Python and Flask
代码运行正常,我想修改函数g()
,但是请求参数不能传递给g()
,它引发了一个RuntimeError: working outside of request context.
我调试了很长时间,不知道怎么修改,你能帮我复习一下代码,解释一下错误背后的原因吗?在
谢谢。在
我的代码是:
@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)))
您需要使用
stream_with_context()
。Reference相关问题 更多 >
编程相关推荐