我有一个小型 Flask 网站,我想从中提供一个 ical feed。
我已经创建了一个经常更新的 ics 文件,但是我不知道如何从网站上提供它。
我尝试通过 Response
和 serve_file
来实现,但它们只显示文件中的文本。
最佳答案
您需要设置正确的 content disposition响应的标题。在您的情况下, header 将类似于以下内容:
Content-Disposition: attachment; filename=calender.ics;
在您的 Flask 路由中,您的代码应如下所示:
from flask import make_response
app = Flask(__name__)
# ...
@app.route('/calendar/')
def calendar():
# Get the calendar data
_calendar = make_calendar()
# turn calendar data into a response
response = make_response(_calendar)
response.headers["Content-Disposition"] = "attachment; filename=calendar.ics"
return response
关于python - 使用 Flask 提供 ical feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44080897/