Python 如何将文本写入Flask中的响应
我的应用程序中有一个端点,当它被击中时,我想向客户端发送响应。我在烧瓶里这样做Python 如何将文本写入Flask中的响应,python,flask,Python,Flask,我的应用程序中有一个端点,当它被击中时,我想向客户端发送响应。我在烧瓶里这样做 from flask import Response def heartbeat(): response = Response() response.headers['Last-Modified'] = datetime.now() response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-c
from flask import Response
def heartbeat():
response = Response()
response.headers['Last-Modified'] = datetime.now()
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
response.headers['Expires'] = '-1'
return response(heartbeat)
这将引发一个错误,该调用包含三个参数。我错过了什么
from flask import Response, Flask
app = Flask(__name__)
@app.route("/")
def heartbeat():
response = Response()
response.headers['Last-Modified'] = datetime.now()
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
response.headers['Expires'] = '-1'
return response
然后访问localhost:5000/就可以了。您应该正确格式化代码!缩进不匹配。我使用make_response修复了它。谢谢