Flask视图返回错误“View函数没有返回响应” [英] Flask view return error "View function did not return a response"
本文介绍了Flask视图返回错误“View函数没有返回响应”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个视图,调用一个函数来获取响应。但是,它给出错误查看函数没有返回响应
。如何解决这个问题?
from flask import Flask
app = Flask(__ name__)
def hello_world():
return'test'
@ app.route('/ hello',methods = ['GET','POST'])
def hello():
hello_world()
$ b $ if if __name__ =='__main__':
app.run(debug = True)
当我尝试通过添加一个静态值而不是调用该函数来测试它时,它就起作用了。
@ app.route('/ hello',methods = ['GET','POST'])
def hello():
returntest
解决方案以下不返回响应: p>
@ app.route('/ hello',methods = ['GET','POST'])
def hello ():
hello_world()
你的意思是说...
$ b $@ app.route('/ hello',methods = ['GET','POST'])
def hello() :
返回hello_ world()
请注意
return
在这个固定的功能。I have a view that calls a function to get the response. However, it gives the error
View function did not return a response
. How do I fix this?from flask import Flask app = Flask(__name__) def hello_world(): return 'test' @app.route('/hello', methods=['GET', 'POST']) def hello(): hello_world() if __name__ == '__main__': app.run(debug=True)
When I try to test it by adding a static value rather than calling the function, it works.
@app.route('/hello', methods=['GET', 'POST']) def hello(): return "test"
解决方案The following does not return a response:
@app.route('/hello', methods=['GET', 'POST']) def hello(): hello_world()
You mean to say...
@app.route('/hello', methods=['GET', 'POST']) def hello(): return hello_world()
Note the addition of
return
in this fixed function.这篇关于Flask视图返回错误“View函数没有返回响应”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文