Flask Sub Function Not Yielding Results
I have a bunch of code (1300 lines) that is working correctly and I am trying to incorporate flask into the picture. In order to do this, I an trying to use flask.Response to call
Solution 1:
Your nested test_method_sub_function()
function doesn't return anything; it simply creates the generator (by calling a generator function), then exits.
It should at the very least return the tc.worker()
call:
def test_method_sub_function():
return tc.worker()
at which point the route works. You may as well skip this nested function however and use tc.worker()
directly:
@app.route('/', methods=['POST'])deftest_method_post_stuff():
return flask.Response(tc.worker(), mimetype='text/plain')
One note: although your use of the Flask
object as a class attribute happens to work, you should to put it in a class. Leave the app
object and routes outside of the class:
import flask
classTestClass(object):
defworker(self):
yield'print test\n'
tc = TestClass()
app = flask.Flask(__name__)
@app.route('/')deftest_method_get_stuff():
return flask.render_template('index.html')
@app.route('/', methods=['POST'])deftest_method_post_stuff():
return flask.Response(tc.worker(), mimetype='text/plain')
app.run(debug=True)
Post a Comment for "Flask Sub Function Not Yielding Results"