带有after_request的基本烧瓶应用程序返回服务器错误 [英] Basic flask application with after_request returns server error

查看:137
本文介绍了带有after_request的基本烧瓶应用程序返回服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  from flask import Flask 
app = Flask(__ name__)
@ app.route('/')
def hello():
返回k?
@ app.after_request
def sendingms():
如果__name__ =='__main__'则传递

app.run()

我做错了什么?或者我理解after_request错误,如果是的话,我真的很感激解释。

文档通常是找到这样的答案的好地方。


你的函数必须带一个参数,一个 response_class 对象,并返回一个新的响应对象或相同的(见 process_response())。



$ p $ @ app.after_request
def sendms(响应):
返回响应


from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():    
    return "k?"
@app.after_request
def sendsms():
    pass
if __name__ == '__main__':
    app.run()

What am I doing wrong? Or do I understand the after_request wrong if so I'd really appreciate an explanation.

解决方案

The documentation is usually a good place to find answers to things like this.

Your function must take one parameter, a response_class object and return a new response object or the same (see process_response()).

Your function does neither of those things.

@app.after_request
def sendsms(response):
    return response

这篇关于带有after_request的基本烧瓶应用程序返回服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆