2013-08-13 28 views
16

Tôi có chế độ xem gọi một hàm để nhận phản hồi. Tuy nhiên, nó đưa ra lỗi View function did not return a response. Làm thế nào để sửa lỗi này?Lỗi trả về chế độ xem bình "Chức năng chế độ xem không trả về phản hồi"

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) 

Khi tôi thử kiểm tra bằng cách thêm giá trị tĩnh thay vì gọi hàm, nó hoạt động.

@app.route('/hello', methods=['GET', 'POST']) 
def hello(): 
    return "test" 

Trả lời

29

Sau đây không trả lại một phản ứng:

@app.route('/hello', methods=['GET', 'POST']) 
def hello(): 
    hello_world() 

Bạn muốn nói ...

@app.route('/hello', methods=['GET', 'POST']) 
def hello(): 
    return hello_world() 

Lưu ý việc bổ sung các return chức năng cố định này.

Các vấn đề liên quan