Flask 视图返回错误“视图函数没有返回响应" [英] Flask view return error "View function did not return a response"
本文介绍了Flask 视图返回错误“视图函数没有返回响应"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个调用函数来获取响应的视图.但是,它给出了错误View function did not return a response
.我该如何解决这个问题?
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"
推荐答案
以下不返回响应:
@app.route('/hello', methods=['GET', 'POST'])
def hello():
hello_world()
你的意思是说...
@app.route('/hello', methods=['GET', 'POST'])
def hello():
return hello_world()
注意在这个固定函数中添加了return
.
Note the addition of return
in this fixed function.
这篇关于Flask 视图返回错误“视图函数没有返回响应"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文