首先,我使用烧瓶。
其次,我yield
喜欢下面的代码。
def upload_file():
if request.method == 'POST':
f = request.files['file']
def generate():
yield '<pre>'
yield "Processing...\n"
file = CheckFile(f.filename, f.read())
file.parse()
for note in file.validate():
if note.oddity_type == Note.ERROR:
yield '<span style="color: red;">%s</span>' % str(note)
if note.type == Note.WARNING:
yield '<span style="color: orange;">%s</span>' % str(note)
if note.type == Note.INFO:
yield '<span style="color: blue;">%s</span>' % str(note)
if note.type == Note.FATAL:
yield '<span style="color: red;">%s</span>' % str(note)
yield '</pre>'
return Response(stream_with_context(generate()))
if request.method == 'GET':
return app.send_static_file('index.html')
所以在__init__ in
CheckFile之后is completed, I
返回values with
yield` 到响应。
我想做的是能够yield
在.__init__
file.parse()